Foo
Easy Tutorial
❮ Event Isimmediatepropagationstopped Misc Callbacks Firewith ❯

jQuery.fn.extend() Method

jQuery Miscellaneous Methods

Example

Adding two methods to jQuery prototype ($.fn)

<label><input type="checkbox" name="foo"> Foo</label>
<label><input type="checkbox" name="bar"> Bar</label>
<script>
$(function () { 
    $.fn.extend({
        check: function() {
            return this.each(function() {
                this.checked = true;
            });
        },
        uncheck: function() {
            return this.each(function() {
                this.checked = false;
            });
        }
    });
    // Using the newly created .check() method
    $( "input[type='checkbox']" ).check();
})
</script>

Definition and Usage

The $.fn.extend() function extends jQuery with one or more instance properties and methods (primarily used for extending methods).

Note: jQuery.fn is the prototype object of jQuery, and its extend() method is used to add new properties and methods to jQuery's prototype. These methods can be called on jQuery instance objects.


Syntax

Parameter Description
object Object type, the specified object to be merged into jQuery's prototype object.

jQuery Miscellaneous Methods

❮ Event Isimmediatepropagationstopped Misc Callbacks Firewith ❯