1 line
2.2 KiB
JSON
1 line
2.2 KiB
JSON
{"name":"triggerHandler","type":"method","title":".triggerHandler()","deprecated":null,"removed":null,"desc":"Execute all handlers attached to an element for an event.","categories":["events/event-handler-attachment","version/1.2"],"entries":[{"return":"Object","signatures":{"added":"1.2","argument":[{"desc":"A string containing a JavaScript event type, such as <code>click</code> or <code>submit</code>.","name":"eventType","type":"String"},{"desc":"An array of additional parameters to pass along to the event handler.","name":"extraParameters","optional":"true","type":"Array"}]},"examples":{"desc":"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.","code":"\n$( \"#old\" ).click(function() {\n $( \"input\" ).trigger( \"focus\" );\n});\n$( \"#new\" ).click(function() {\n $( \"input\" ).triggerHandler( \"focus\" );\n});\n$( \"input\" ).focus(function() {\n $( \"<span>Focused!</span>\" ).appendTo( \"body\" ).fadeOut( 1000 );\n});\n","html":"\n<button id=\"old\">.trigger( \"focus\" )</button>\n<button id=\"new\">.triggerHandler( \"focus\" )</button><br><br>\n\n<input type=\"text\" value=\"To Be Focused\">\n"},"longdesc":"\n <p>The <code>.triggerHandler()</code> method behaves similarly to <code>.trigger()</code>, with the following exceptions:</p>\n <ul>\n <li>The <code>.triggerHandler()</code> method does not cause the default behavior of an event to occur (such as a form submission).</li>\n <li>While <code>.trigger()</code> will operate on all elements matched by the jQuery object, <code>.triggerHandler()</code> only affects the first matched element.</li>\n <li>Events created with <code>.triggerHandler()</code> do not bubble up the DOM hierarchy; if they are not handled by the target element directly, they do nothing.</li>\n <li>Instead of returning the jQuery object (to allow chaining), <code>.triggerHandler()</code> returns whatever value was returned by the last handler it caused to be executed. If no handlers are triggered, it returns <code>undefined</code></li>\n </ul>\n <p>For more information on this method, see the discussion for <code><a href=\"/trigger/\">.trigger()</a></code>.</p>\n "}]} |