Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery.fn.extend() method

jQuery.fn.extend() method

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods

Example

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 jQuery with one or more instance properties and methods (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 )

Parameters Description
object Object type: The specified object to merge into the jQuery prototype object.

jQuery Miscellaneous MethodsjQuery Miscellaneous Methods