xpath-dom

0.2.2 • Public • Published

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.

Sauce Test Status

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"))

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.2.2
    277
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.2.2
    277
  • 0.2.1
    0
  • 0.2.0
    0
  • 0.1.1
    1
  • 0.1.0
    0

Package Sidebar

Install

npm i xpath-dom

Weekly Downloads

278

Version

0.2.2

License

MIT

Last publish

Collaborators

  • johannhof