var links = document.evaluate("//BODY/CENTER[1]/P[1]/TABLE[1]/TBODY[1]/TR[1]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).evaluate("//A");
basically I need to find an element via xpath. then search this element via xpath. The above doesn’t work obviously but neither does using contextNode argument.
var headings = document.evaluate("//BODY/CENTER[1]/P[1]/TABLE[1]/TBODY[1]/TR[1]", document, null, XPathResult.ANY_TYPE, null);
var thisHeading = headings.iterateNext();
var headings2 = document.evaluate("//A", thisHeading, null, XPathResult.ANY_TYPE, null);
headings2.iterateNext().style.backgroundColor = "red";
I need to be able to search for children of an element via xpath.
You have to use
XPathResult.FIRST_ORDERED_NODE_TYPEin conjunction withsingleNodeValueto get the first element of the XPath expression. Then, use.//Ato select any<a>element, which is a child of the matched node. If you want to match a direct child, use./A: