I was wondering why in so many jquery plugins $(this) is set to be pointing at $this, here is an example, if i have the following two plugins included on a page:
(function($) {
jQuery.fn.pluginOne = function() {
return this.each(function() {
$this = $(this); <--
alert($this);
});
};
})(jQuery)
(function($) {
jQuery.fn.pluginTwo = function() {
return this.each(function() {
$this = $(this); <--
alert($this);
});
};
})(jQuery)
When i call both plugins on dom ready:
$(document).ready({
$('.myClass').pluginOne();
$('.myOtherClass').pluginTwo();
});
The first plugin will get $this from the second plugin... while it i point $(this) to a local var:
(function($) {
jQuery.fn.pluginTwo = function() {
return this.each(function() {
var trigger = $(this); <--
alert(trigger);
});
};
})(jQuery)
everything works at it should, of course...
So my question is... when should I use $this?
Thanks