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

jQuery triggerHandler() method

jQuery triggerHandler() method

jQuery event methods jQuery event methods

Example

Triggers The select event of the element:

$

(

"

button

"

)

.

click

(

function

(

)

{

$

(

"

input

"

)

.

triggerHandler

(

"

select

"

)

;

}

)

;

Try it »


Definition and Usage

The triggerHandler() method fires the specified event on the selected elements.

The return value of this method is the return value of the event handler, rather than a chainable jQuery object. In addition, if no handler is triggered, this method returns undefined.

This method is similar to the trigger() The methods are similar, except that trigger() also fires the event's default behavior (such as form submission).

Differences compared with the trigger() method:

Example

Comparing triggerHandler() with .trigger():

$

(

"

#old

"

)

.

click

(

function

(

)

{

$

(

"

input

"

)

.

trigger

(

"

focus

"

)

;

}

)

; $

(

"

#new

"

)

.

click

(

function

(

)

{

$

(

"

input

"

)

.

triggerHandler

(

"

focus

"

)

;

}

)

; $

(

"

input

"

)

.

focus

(

function

(

)

{

$

(

"

Focused!

"

)

.

appendTo

(

"

body

"

)

.

fadeOut

(

1000

)

;

}

)

;

Try it »


Syntax

$(

selector

).triggerHandler(

event,param1,param2,...

)

Parameters Description
event Required. Specifies the event to trigger on the given element.
param1,param2,... Optional. Extra arguments to pass to the event handler.
Extra arguments are especially useful for custom events.

More examples

Passing extra arguments to a custom event
How to pass extra arguments to a custom event handler.

The difference between trigger() and triggerHandler()
Demonstrates the difference between trigger() and triggerHandler().


jQuery event methods jQuery event methods