How to get selector from jquery object?

codes:

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

Is it possible to get "#readme" from jqueryObj? as:

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

BTW: I want to get a selector, not an element identifier, and jqueryObj.length == 0.

+3
source share
3 answers

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

+4
source

Edit: Removed β€œhalf page with incorrect code” due to endless discussion. See decezes answers for a complete solution ...

+1
source
$('#ggggg').selector 

is the correct way to get a selector for a jQuery object.

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

0
source

Source: https://habr.com/ru/post/1750971/


All Articles