Over a million developers have joined DZone.

XPath Selection

DZone's Guide to

XPath Selection

Free Resource
//test post

//Select elements based on an xpath expression.  Modified from the sample provided at greasemonkey's wiki.  Replaced array copy of elements with a closure to return snapshot item.

//p = xpath expression
//context = context the expression is evaluated on. e.g., document.
//returns snapshot of the xpath evaluation (i.e., elements, possibly attributes).

	function $XPathSelect(p, context) 
	  if (!context) context = document;
	  var xpr = document.evaluate(p, context, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	  return function(x) { return xpr.snapshotItem(x); };

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}