Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why do I get nextElementSibling is not a function?

please see here:

Basically, I’m trying what should be the es6 version of jquery’s next() dom utility. It doesn’t work. Why? Given this example, and succefully referenced the button, button.nextElementSibling() will throw an error saying nextElementSibling is not a function. Why?

window.addEventListener('load', function(){
  const b = document.querySelector('.b');
  console.log(b.nextElementSibling());  
});
<button class="b">button</button>
<div class="test">test</div>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Well, nextElementSibling is not a function, it is a property

window.addEventListener('load', function(){
  const b = document.querySelector('.b');
  // I removed the ()
  console.log(b.nextElementSibling);  
});
<button class="b">button</button>
<div class="test">test</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading