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

Ryan Schmelter
Ryan Schmelter
9,710 Points

Using the same code as in the video, I didn't use the if statement. It still works. Wondering why?

I didn't use the if statement to prevent last list item from jumping to the top when pressing the down button. The code works (it's the same as in the video, just without the if statement). And still the list items doesn't jump with this conditional. Any explanation why this would be the case?

Peter Csakany
Peter Csakany
3,925 Points

When you want to move the last element down it wouldn't jump to the top as if you check the code we are moving the next element above the current one hence the illusion that it's moving down. By the last element there is no next element to move so you won't see any change the page works although the console will show you an error message if you inspect the page.