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
  • 1
    JavaScript in Firefox seems to have a method to evaluate XPath, but that is probably not convenient: developer.mozilla.org/en/… Commented Sep 23, 2010 at 22:27

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

-2

You can use xpath directly in the selector though:

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

2 Comments

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

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.