Example of the use of jquery $.fn

Source: Internet
Author: User

$.fn refers to the jquery namespace, plus the methods and properties on the FN, which are valid for each jquery instance.

If the extension $.fn.abc (), or $.FN.ABC () is a method of extending an ABC to jquery, then each jquery instance can invoke the method.

For example: $ ("#div"). ABC ();

jquery provides two methods for development, namely:

Jquery.extend (object); To extend the jquery class itself, add a new method to the class.

Jquery.fn.extend (object); Adds a method to a jquery object.

Example:

$.extend ({    add:function (b) {return a +b;}}) Can be understood as a static method, the actual invocation of $.add (3,4); // 7

$. ("#btn1") generates an instance of the jquery class.

Jquery.fn.extend (object); To extend the jquery.prototype is to add "member functions" to the jquery class, and the jquery instance can use "member functions".

For example to develop a plugin, make a special edit box when he is clicked, then alert the current edit box contents

$.fn.extend ({alertwwhileclick:function () {$ (this). Click (function () {  alert ($ (  this). Val ()); })})

Example of the use of jquery $.fn

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.