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>

>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>

Leave a Reply