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.

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 30/11/2020
3176 People Used
Only 97 Left
Rating
5.0