jquery select element by xpath

Quamis picture Quamis · Jun 23, 2011 · Viewed 132.5k times · Source

I have an xpath selector. How can I get the elements matching that selector using jQuery?

I've seen https://developer.mozilla.org/en/Introduction_to_using_XPath_in_JavaScript but it doesn't use jQuery, and it seems a little too verbose, and I suppose it's not cross-browser.

Also, this http://jsfiddle.net/CJRmk/ doesn't seem to work.

Answer

Jeppe Liisberg picture Jeppe Liisberg · Jun 13, 2013

If you are debugging or similar - In chrome developer tools, you can simply use

$x('/html/.//div[@id="text"]')