I know the difference between $.fn.extend
and $.extend
. But what is the difference between $.fn
and $.fn.extend
? When should I use one or the other? In the jQuery learning center for implementing jQuery plugins, I cannot find any examples that use $.fn.extend
or discuss when to use $.fn.extend
and when to use $.fn
.
Thank you.
Take a very basic example:
$.fn.greenify = function() {
this.css( "color", "green" );
};
$( "a" ).greenify(); // Makes all the links green.
$.fn.extend({
greenifyP: function() {
return this.css( "color", "green" );
}
});
$( "p" ).greenifyP();
// html
<a href="http://www.google.com">test</a>
<p>test</p>
Are the two methods exactly the same under the covers? I'm trying to determine when would I use $.fn.extend
, as opposed to $.fn
and if they are equivalent?