In jQuery, I have seen both the following ways of defining a jQuery function:
$.fn.CustomAlert = function() {
alert('boo!');
};
$.CustomAlert = function() {
alert('boo!');
};
I understand that they are attached to the jQuery object (or $), but what is the difference between the two? When should I use one or the other?
Thanks.
Source: Tips4all
A
ReplyDelete$.a = function() {
return "hello world";
};
alert($.a());
B
$.fn.b = function() {
return "hello " + $(this).length + " elements";
}
alert($("p").b());