JQuery selector help – Can I generate a selector from clicking on an element

css-selectorsfirebugie-developer-toolsjquery

I have jQuery, FireFox, Firebug, IE, and IE developer toolbar. When I am examing a page with either FireBug or IE Dev toolbar, I am able to click on an element and it shows me in the dom where the element is etc… Is there anyway to transform that selection into a valid jQuery selector? I know I can use ID, classes, and element relative to other elements etc… but what about when I am looking at some random table cell that doesn't have a class or id etc.. Can I generate a selector on the fly like that? I thought for sure there was. Any thoughts or ideas are always appreciated

Thanks,
~ck in San Diego

Best Answer

There are a couple of free tools that will help you find your selector. One is called Selector Detector and the other is SelectorGadget.

Both are very similar and easy to implement. Just bookmark a javascript link and open it on your site (just like firebug lite). Then click on your element to display its selector.

I just wrote an article comparing the two that includes demos and download links. If you want to read more, check it out here: http://www.heinencreative.com/archives/articles/selector-detector-vs-selectorgadget/