I'm trying to get all elements containing a string:
function getElementsByText( text, ctx) {
return document.evaluate(
"//*[.='"+text+"']",
ctx || document,
null,
XPathResult.ORDERED_NODE_ITERATOR_TYPE,
null
).iterateNext();
}
var searchString = "Name";
var parents = getElementsByText(searchString);
for (var i = 0; i < parents.length; i++) {
parents[i].style.opacity = .2;
};
The docs say evaluate with ORDERED_NODE_ITERATOR_TYPE returns "all the nodes matching the expression". But getElementsByText returns only the first occurrence.
This code doesn't work because parents is not iterable.
How can I get all the elements?