.triggerHandler()
methodThe .triggerHandler()
method in jQuery is used to execute all handlers for an event that attached to an element(the first matched element).
.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. |
.triggerHandler()
method ExampleIf 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); });