Phil Whittaker
Phil Whittaker

Reputation: 434

Jquery object selector as string

Is there any way to get the selector for a jquery object

e.g in firefox I see a jquery object as [p.basket]

but there seems to be no way in jquery that I can get this selector?

Is there any way?

Phil

Upvotes: 2

Views: 1569

Answers (2)

Pointy
Pointy

Reputation: 413712

If a jQuery object was created with a selector string, then you can just look at its "selector" property. However, not all jQuery objects are so constructed. Thus you should make sure to check for null.

edit — if your jQuery object was not constructed with a selector, then there simply is not a selector available. The library does not have any built-in way of creating a selector that matches the set of elements it contains. You could do that yourself, though it's not clear why it would be useful; once you have a reference to the DOM elements (which you do if the jQuery object isn't empty), isn't that more useful?

Upvotes: 2

Steve
Steve

Reputation: 15736

Is the selector property what you want?

Upvotes: 1

Related Questions