DEV Community

Md Abdullah al noor
Md Abdullah al noor

Posted on

traversing not working | nextelementsibling giving null js

i am working for a client project .. i need to do toggle class through dom traversal..

when click on title i am getting null for nextElementSibling

some pieces of html structure ..

   document.querySelectorAll(".viewAbstractToggleTitle").forEach(function(item){

          item.addEventListener("click",function(e){

          if(e.target.parentElement.classList.contains('viewAbstractToggleTitle')){
            console.log(e.target.parentElement.nextElementSibling.nextElementSibling)
            console.log(e.target.parentElement.nextElementSibling.nextElementSibling.nextElementSibling)
            
          }

          })
          })
  <li style="border-bottom: 1px solid #d6d6d6;margin-bottom:10px;">
  <a

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay