JQuery selector creator?

I was wondering if such a tool exists in the browser. You select any element on the page as a <p> tag embedded in several divs, and the tool creates a JQuery selector for it, which I can copy and use in my Javascript function.

+4
source share
4 answers

I think you should check out SelectorGadget . This is a JavaScript bookmarklet that allows you to interactively select elements on a page and splash out an exact DOM-based targeting selector.

Its pretty advanced, watch the screencast!

+6
source

You can always use the element itself as a selector. For example, using $ (this) inside a click handler wraps the current element inside a jQuery object.

 $('p').click( function() { var html = $(this).html(); ... more computing... }); 

If you need a row selector for a specific element, this will be harder. You will need to go back up using parent () and prev () (to get offsets for similar elements at each level), unless the element has an identifier then you can just use it.

You might be better off creating a unique class that you can assign and reference it this way.

 var counter = 0; $('p').click( function() { var uniq = 'paragraph-' + counter; ++counter; $(this).addClass(uniq); }); 
+3
source

You can also use the XPather plugin for FF as an assistant in your task.

http://xpath.alephzarro.com/

It shows an XPATH element that can help you understand what it is from a DOM perspective.

0
source

I think this Chrome plugin is exactly what you are looking for: JQuery Unique Selector

0
source

All Articles