what does the "this-keyword" reference to in this context:
jQuery.fn.m=function (){
console.log(this == $("#diveins")); // gives a false what does it reference to?
};
$("#diveins").m();
what does the "this-keyword" reference to in this context:
jQuery.fn.m=function (){
console.log(this == $("#diveins")); // gives a false what does it reference to?
};
$("#diveins").m();
In a jQuery method,
thisis the jQuery collection that you called the method on. So in your example, it's the collection returned by$("#diveins").The reason you get
falseis because every time you call$("#diveins")you get a new collection. If you wrote:it will also show
false.You can use
this.is("#diveins"). This will work if you're just looking for a single element -- there doesn't seem to be an easy way to compare jQuery collections.