javascript - why is jQuery selector property undefined within each()? -


Looking at the following code, why does the selector properties work in the first instance but not the second? Are not they both jQuery objects?

  & lt; Span class = 'tst' & gt; Span & lt; / Span & gt; One ???? Var tst = $ ('.tst'); Console.log (tst.selector); // print '.tst' $ ('.tst'). Each (function () {console.log (this.selector);}); // print undefined ???? Line Line Line Formula ??? In the context of    

this , .each ( ) Loop is not a jQuery object, so the selector property is undefined.

You first need to create a jQuery object: $ (this). Selector

However, it should be noted that the selector property returns an empty string while inside .each loop.

Edit

If you have a selector in the property .each () , an option will be sent to your The selector will have to cache:

  var cached = $ ('.tst'); Cached.each (function () {console.log (cached.selector); // will appear ".tst"});   

one ????

Comments