Given the following code, why does the selector property work in the first instance but not the second? Aren’t they both jQuery objects?
<span class='tst'>span</span>
var tst = $('.tst');
console.log(tst.selector);
// prints '.tst'
$('.tst').each(function() { console.log(this.selector);});
// prints undefined
this, in the context of the.each()loop, is not a jQuery object, so theselectorproperty is undefined.You need to make it a jQuery object first:
$(this).selectorHowever, it should be noted that the
selectorproperty will return an empty string while inside the.each()loop.Edit
If you absolutely need the
selectorproperty within the.each(), one option would be to cache your selector: