jQuery Tutorial Tutorials - jQuery .triggerHandler() method

jQuery .triggerHandler() method

The .triggerHandler() method in jQuery is used to execute all handlers for an event that attached to an element(the first matched element).

jQuery .triggerHandler() method Syntax

.triggerHandler(eventType[,extraParameters])
Parameter Type Description
eventType String JavaScript event type,such as click,submit.
extraParameters Array,PlainObject Extra data to be passed to the event handler.

jQuery .triggerHandler() method Example

example

If you called .triggerHandler() on a focus event - the browser's default focus action would not be triggered, only the event handlers bound to the focus event.

HTML

<button id="old">.trigger("focus")</button>
<button id="new">.triggerHandler("focus")</button><br/><br/>
<input type="text" value="To Be Focused"/>

jQuery

$("#old").click(function () {
    $("input").trigger("focus");
});
$("#new").click(function () {
    $("input").triggerHandler("focus");
});
$("input").focus(function () {
    $("<span>Focused!</span>").appendTo("body").fadeOut(1000);
});

Try now

Date:2019-08-29 23:53:42 From:www.Lautturi.com author:Lautturi