Get the Next Element with JavaScript nextElementSibling

Web Dev
Sponsored links

In this article, I will introduce how to get the next element with JavaScript nextElementSibling.

What is nextElementSibling?

The nextElementSibling is a property that allows you to get the next element of the specified element.

The syntax is as follows.

let element = document.getElementById('element');


What you can get with nextElementSibling is a sibling element that has the same parent element except for the text node and comment node.

Sponsored links

Get the next element with nextElementSibling

Get the next element adjacent to the element with the specified id.


  <li id="target"></li>


let element = document.getElementById('target');