Languages
[Edit]
EN

JavaScript / XPath - get next element to current one

7 points
Created by:
a_horse
478

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>
<html>
<body>
  <div>
    <div id="element">User ID</div>
    <div>5f7c2487</div>
  </div>
  <script>
    
    var currentElement = document.querySelector('#element');

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

    if (nextElement) {
      console.log(nextElement.innerText);
    }
    
  </script>
</body>
</html>

 

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.

❤️💻 🙂

Join