Could someone please explain a bit, what difference between them?
For example I could do that with “that”:
var bar;
button.click(function () {
if (bar == this) {
alert('same');
}
bar = this;
});
and couldn’t with $(that):
var bar;
button.click(function(){
if(bar == $(this)) {alert('same');}
bar = $(this);
});
Your second example doesnt work, because every time you use the
$(this)function, it returns an unique jQuery Object:Now, b and c are both unique jQuery instances.
When using jQuery click events,
thisis the event.currentTarget in the callback, which is the HTML element that bound the click:$(this)orjQuery(this)is a function that returns the HTML element wrapped in a unique jQuery Object, and contains all jQuery prototypes.