Easily use XPath with the DOM
npm install xpath-dom --save
Browser Compatibility
All browsers support XPath really well except for IE. For IE support please use Google's awesome wicked-good-xpath shim.
Usage
xpath-dom supports AMD, CommonJS and includes via script tag, where it exposes the xpath
global.
var xpath = ;
xpath.find(expression [, relativeTo])
Finds a DOM node by the specified XPath. Returns the first Node that matches the path.
Can be passed a DOM node to set as the relative root node.
xpath
xpath
xpath.findAll(expression [, relativeTo])
Finds all DOM nodes that match the specified XPath.
Can be passed a DOM node to set as the relative root node.
xpath
xpath.getXPath(node [, relativeTo])
Returns a concise XPath given a DOM node. The XPath will match the given node, but it is not guaranteed to uniquely match that node, e.g. there might be other nodes that will be matched by that XPath in the document.
Can be passed a DOM node to set as the relative root node.
xpath
xpath.getUniqueXPath(node [, relativeTo])
Returns a unique but slightly more verbose XPath given a DOM node.
Can be passed a DOM node to set as the relative root node.
xpath