EN
JavaScript / XPath - get next element to current one
7
points
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>