Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to used xpath snapshot in loop

var xpath = "//div";
var result = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var node = null;
var tagNames = [];
for(var i = 0; i < result.snapshotLength; i++) {
  var node = result.snapshotItem(i);
  tagNames.push(node.localName);
}
document.querySelector("output").textContent = tagNames.join(", ");
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #xpath #snapshot #loop
ADD COMMENT
Topic
Name
9+7 =