JavaScript JavaScript and the DOM Traversing the DOM Solution: Using nextElementSibling

Aakash Srivastav
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,612 Points

Using nextSibling()

Can i use this as a solution to the problem mentioned in the video-

 if ( == 'down') {
      let li =;
      let nextLi = li.nextElementSibling;
      if (nextLi) {
        let temp = nextLi ; 
        nextLi = li ; 
        li = temp;

1 Answer

Steven Parker
Steven Parker
182,307 Points

It looks like your code just changes the values in your variables. But the code in the video calls the "insertBefore" method to make changes happen on the page.