1

I need a way to select elements via xpath (NOT CSSpath or any other method, must strictly be xpath)

$(document).find("/html[1]/body[1]/div[4]/div[2]/div[1]/h1[1]/a[1]").css("background-color", "yellow")

This doesn't seem to work.

1

3 Answers 3

6

The support for XPATH selectors was dropped from jQuery. In version 1.2 from what I can gather.

0

The method find() uses a CSS Selector, not a XPath select.

-2

You can use xpath directly in the selector though:

http://dev-tips.com/featured/jquery-tip-using-xpath-selectors

2
  • 1
    This is not actually XPath: this is something jQuery confusing calls an "XPath Selector", which does not even remotely attempt to support "XPath", and over time has become less and less capable (such as in jQuery 1.3, where they decided "@" wasn't valid syntax anymore). The correct answer, AFAIK, is Guffa's answer below: jQuery seems to no longer support XPath as of 1.2 (which really sucks, and I'd love it if someone told me I was wrong). Sep 1, 2011 at 4:35
  • JQuery developers deprecated XPath following JQuery version 1.2 .. and now only use a plugin to accomplish this. Just use the regular JavaScript function "document.evaluate" to find the element object based on XPath. Apr 12, 2012 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.