Skip to content

Commit 2009534

Browse files
phistuckkswedberg
authored andcommitted
.trigger(): invoking the on(event-type) property of an object
note that calling .trigger(event-type) on an object invokes the on(event-type) property of that object Closes gh-509
1 parent 44fb821 commit 2009534

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

entries/trigger.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ $( "#foo").trigger( "custom", [ "Custom", "Event" ] );
4545
<p>Note the difference between the extra parameters passed here and the <code>eventData</code> parameter to the <a href="/on/">.on()</a> method. Both are mechanisms for passing information to an event handler, but the <code>extraParameters</code> argument to <code>.trigger()</code> allows information to be determined at the time the event is triggered, while the <code>eventData</code> argument to <code>.on()</code> requires the information to be already computed at the time the handler is bound.</p>
4646
<p>The <code>.trigger()</code> method can be used on jQuery collections that wrap plain JavaScript objects similar to a pub/sub mechanism; any event handlers bound to the object will be called when the event is triggered. </p>
4747
<div class="warning"><strong>Note:</strong> For both plain objects and DOM objects other than <code>window</code>, if a triggered event name matches the name of a property on the object, jQuery will attempt to invoke the property as a method if no event handler calls <code>event.preventDefault()</code>. If this behavior is not desired, use <code>.triggerHandler()</code> instead.</div>
48+
<div class="warning"><strong>Note:</strong> As with <code>.triggerHandler()</code>, when calling <code>.trigger()</code> with an event name matches the name of a property on the object, prefixed by <code>on</code> (e.g. triggering <code>click</code> on <code>window</code> that has a non null <code>onclick</code> method), jQuery will attempt to invoke that property as a method.</div>
4849
</longdesc>
4950
<example>
5051
<desc>Clicks to button #2 also trigger a click for button #1.</desc>

0 commit comments

Comments
 (0)