xpath-dom
v0.2.2
Published
Easily use XPath with the DOM
Downloads
1,204
Readme
xpath-dom
Easily use XPath with the DOM
npm install xpath-dom --save
<script src="https://cdn.rawgit.com/johannhof/xpath-dom/master/dist/xpath-dom.min.js"></script>
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 = require('xpath-dom');
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.find("div/span[1]")
xpath.find("div/span[1]", document.getElementById('main'))
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.findAll("div/span[1]")
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.getXPath(document.getElementById("headline"))
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.getUniqueXPath(document.getElementById("headline"))