Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 426
Tony_Henrich Avatar asked Sep 28 '11 19:09

Tony_Henrich


People also ask

Can we use XPath in jQuery?

The jQuery library supports a basic set of XPath selectors that we can use alongside CSS selectors, if we so desire. And with jQuery, both XPath and CSS selectors can be used regardless of the document type.

Which jQuery selector is fastest?

ID and Element selector are the fastest selectors in jQuery.

Which selector does jQuery use to select?

The jQuery #id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the #id selector when you want to find a single, unique element.


2 Answers

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

like image 101
Tony_Henrich Avatar answered Oct 05 '22 18:10

Tony_Henrich


enter image description here

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

like image 32
cetver Avatar answered Oct 05 '22 18:10

cetver