🚨 Time is Running Out: Reserve Your Spot in the Lucky Draw & Claim Rewards! START NOW

Code has been added to clipboard!

Understanding and Using jQuery .triggerHandler() in Your Code

Reading time 1 min
Published Jan 10, 2018
Updated Oct 2, 2019

jQuery triggerHandler: Main Tips

  • The jQuery .triggerHandler() method runs handlers assigned to an element for an event.
  • .trigger() executes handlers on all detected elements. The jQuery .triggerHandler() influences the first matched element.

How .triggerHandler() Work

The .triggerHandler() lets you trigger jQuery handler of the specified event on the selected element.

Example
$("button").click(() => {
    $("input").triggerHandler("select");
});

The syntax for jQuery .triggerHandler() is similar to trigger jQuery method:

$("selector").triggerHandler(event, [parameter1], [parameter2], ..., [parameterN]);

This method takes two parameters:

  • event represents a standard JavaScript event or a custom jQuery.event object.
  • parameter means you may also add multiple parameters to be passed to the event handler function.

Note: unlike the .trigger() jQuery method, .triggerHandler() includes the handler function only, and not the default event behavior.