Languages
[Edit]
EN

JavaScript / XPath - get next element to current one

7 points
Created by:
a_horse
208

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>

 

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