Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (43 sloc) 2.3 KB
<?xml version="1.0"?>
<entry type="method" name="triggerHandler" return="Object">
<title>.triggerHandler()</title>
<desc>Execute all handlers attached to an element for an event.</desc>
<signature>
<added>1.2</added>
<argument name="eventType" type="String">
<desc>A string containing a JavaScript event type, such as <code>click</code> or <code>submit</code>.</desc>
</argument>
<argument name="extraParameters" optional="true" type="Array">
<desc>An array of additional parameters to pass along to the event handler.</desc>
</argument>
</signature>
<longdesc>
<p>The <code>.triggerHandler()</code> method behaves similarly to <code>.trigger()</code>, with the following exceptions:</p>
<ul>
<li>The <code>.triggerHandler()</code> method does not cause the default behavior of an event to occur (such as a form submission).</li>
<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>
<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>
<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>
</ul>
<p>For more information on this method, see the discussion for <code><a href="/trigger">.trigger()</a></code>.</p>
</longdesc>
<example>
<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.</desc>
<code><![CDATA[
$("#old").click(function(){
$("input").trigger("focus");
});
$("#new").click(function(){
$("input").triggerHandler("focus");
});
$("input").focus(function(){
$("<span>Focused!</span>").appendTo("body").fadeOut(1000);
});
]]></code>
<html><![CDATA[<button id="old">.trigger("focus")</button>
<button id="new">.triggerHandler("focus")</button><br/><br/>
<input type="text" value="To Be Focused"/>]]></html>
</example>
<category slug="events/event-handler-attachment"/>
<category slug="version/1.2"/>
</entry>
Jump to Line
Something went wrong with that request. Please try again.