What are the expansion methods in jquery
This article will explain in detail what are the expansion methods in jquery. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Extension method in jquery
.fn refers to the namespace of jquery, plus the methods and properties on fn, which will be valid for each jquery instance.
If the extension $.fn.ABC (), that is, $.fn.abc () extends an abc method to jquery, then every subsequent jquery instance can refer to this method.
Then you can go like this: $("# div"). Abc ()
JQuery.extend (object); to extend the jQuery class itself. Add a new method to the class.
JQuery.fn.extend (object); add methods to the jQuery object.
JQuery.extend (object); adding class methods to the jQuery class can be understood as adding static methods. Such as:
Elem.animate ({'width':200}, 1000); / / whether elem.is (': animated') & & console.log ("it is animated!") is being animated
Add a "static method" for jQuery as add, which can then be used where jQuery is introduced
$.add (3 return 4); / / add 7
JQuery.fn.exists = function () {return this.length > 0;} console.log ($('# elem') .exists ()? "exists!": "doesn't exist!") this is the end of the article on "what are the expansion methods in jquery?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.