JavaScript / XPath - get next element to current one

7 points
Created by:

In this short article we would like to show how to get next one element to current one using XPath and JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

<!doctype html>
    <div id="element">User ID</div>
    var currentElement = document.querySelector('#element');

    var result = document.evaluate('following-sibling::*', currentElement);
    var nextElement = result.iterateNext();

    if (nextElement) {


Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript / XPath

Native Advertising
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂