tags:

views:

75

answers:

3

codes:

   var jqueryObj=$("#readme");
   alert(jqueryObj.length); // result == 0

can i get "#readme" from jqueryObj ? like:

   alert(jqueryObj.selector); //i want get "#readme"

BTW: i want to get selector,not element ID, and jqueryObj.length == 0.

+4  A: 

Uhm... have you tried? http://api.jquery.com/selector/

deceze
thank you! i'm so stupid :-P
Zenofo
A: 
$('#ggggg').selector 

is the correct way of getting the selector for the jQuery object.

This is what you had in your original post, have you tried it?

DannyLane
A: 

Edit: Deleted 'half a page of incorrect code' due to endless discussion. Refer to decezes answer for complete solution ...

air_blob
The jQuery object's `.length` attribute has absolutely nothing to do with how many times an element is allowed to appear on the page. Also, if it did match an element, even just one, `.length` is `1`.
deceze
Read carefully: I said an elements ID has to be unique!But your right with the length ...
air_blob
I never disputed that an id has to be unique, it just has nothing to do with the question or your explanation. Even with your correction, the rest is still nonsense. You **can** use `.selector` on the jQuery object, even if it contains more than one result.
deceze
Come on ... I never said that you can't use .selector. lazyanno asked 'can i get "#readme" from jqueryObj ?' (read: an ID!) and I explained how ... sorry that I overread the 'BTW' and tried to help with a detailed solution. Next time I'll just post some link to an API Doc and start moaning around, too ... :-)
air_blob
Actually, you *did* say "here you can't use .selector". And I'm not moaning, I'm snootily pointing out an incorrectness. ;P Sorry if you feel that an (apparently) helpful 4 word answer is worse than half a page of incorrect code.
deceze