jQuery Event - triggerHandler() Method
Example
Trigger the select event of the input element:
$("button").click(function(){ $("input").triggerHandler("select"); });
Definition and Usage
The triggerHandler() method triggers the specified event type on the selected element but does not execute the browser's default actions, nor does it produce event bubbling.
The triggerHandler() method is similar to the trigger() method. The difference is that it does not trigger the default behavior of events (such as form submission) and only affects the first matching element.
Differences from the trigger() method
- It does not cause the default behavior of events (such as form submission)
- .trigger() operates on all elements that match the jQuery object, while .triggerHandler() only affects the first matching element.
- Events created by .triggerHandler() do not bubble in the DOM tree; nothing happens if the target element does not handle them directly.
- This method returns the return value of the event handler, not a chainable jQuery object. Moreover, if no handler is triggered, this method returns undefined.
Trigger Event
Specifies the event to be triggered on the selected element.
Syntax
$(selector).triggerHandler(event,param1,param2,...])
Parameters | Description |
---|---|
event | Required. Specifies the event to be triggered on the specified element. |
[param1,param2,...] | Optional. Additional parameters passed to the event handler. |