开发者

Tool to convert an XPath to a jQuery selector?

Firebug is able to display the xpath for any DOM element in the HTML view. I was wondering if 开发者_JAVA技巧there's a way to convert the xpath to a jQuery selector? (I prefer not to do this manually)

This will greatly save me time to find the correct selector for elements which don't have an id & are way deep in the DOM hierarchy. For example the fifth TD in the 20th TR

AFAIK, xpath support in jQuery is dropped so I can't use the xpath straight in jQuery?


There's a 'copy css path' in Firebug when right-clicking an element. It can be used to create a selector.


Tool to convert an XPath to a jQuery selector?

https://addons.mozilla.org/en-US/firefox/addon/firepath/


I'm not sure if you are asking a general question abotu converting XPath to CSS selector, but I found this post jquery: selecting xpath or converting xpath to css? which might be of help. It reccomends using "eq" method to select an element by index. So the fifth TD in the 20th TR would be

$('tr').eq(20).find('td').eq(5)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜