jQuery.fn.extend()Method
Examples
Add two methods to the 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;
});
}
});
//Use the newly created .check() method
$( "input[type='checkbox']" ).check();
})
</script>
Try it »
Definition and Usage
The $.fn.extend() function extends one or more instance properties and methods for jQuery (mainly used to extend methods).
Tip:jQuery.fn is the prototype object of jQuery. Its extend() method is used to add new properties and methods to the jQuery prototype. These methods can be called on jQuery instance objects.
Syntax
$.fn.extend( object )
| Parameter | Description |
|---|---|
| object | Object type. Specifies the object to be merged into the jQuery prototype object. |
Other extensions
jQuery Miscellaneous Methods