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.
alert($("//a").length);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script> <a href="a1.php"></a> <a href="a2.php"></a>
If you are debugging or similar - In chrome developer tools, you can simply use
$x('/html/.//div[@id="text"]')
1.4m articles
1.4m replys
5 comments
57.0k users