jQuery triggerHandler()Method
Example
Trigger the select event of the <input> element:
Try it Yourself »
Definition and Usage
The triggerHandler() method triggers the specified event on the selected element.
This method returns the return value of the event handler function, rather than a chainable jQuery object. In addition, if no handler is triggered, this method returns undefined.
This method is similar to thetrigger()method, the difference being that trigger() also triggers the default behavior of the event (like form submission).
Differences compared to the trigger() method:
- It does not cause the default behavior of the event (such as form submission)
- .trigger() operates on all elements matched by the jQuery object, while .triggerHandler() only affects the first matched element.
- Events created by .triggerHandler() do not bubble up the DOM tree; if the target element does not directly handle them, nothing will happen.
Example
Comparing triggerHandler() with .trigger():
Try it Yourself »
Syntax
| Parameter | Description |
|---|---|
| event | Required. Specifies the event to trigger on the specified element. |
| param1,param2,... | Optional. Additional parameters passed to the event handler. Additional parameters are especially useful for custom events. |
More Examples
Passing additional parameters to custom events
How to pass additional parameters to a custom event handler.
The difference between trigger() and triggerHandler()
Demonstrates the difference between trigger() and triggerHandler().
Other Extensions
jQuery Event Methods