Side navigation
#10320 closed bug (invalid)
Opened September 20, 2011 03:10PM UTC
Closed September 20, 2011 04:35PM UTC
Last modified November 19, 2012 08:39PM UTC
pass a jquery object as trigger data
Reported by: | thierry@hydromail.net | Owned by: | |
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | event | Version: | 1.6.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
$('#elt').bind('z', function( event, obj) { console.log(obj); }); $('#elt').trigger('z', $('#elt'));
I would expect the handler will display a jquery object (actually, the one I passed as a parameter). Instead, it displays the DOM #elt object.
Attachments (0)
Change History (3)
Changed September 20, 2011 04:35PM UTC by comment:1
component: | unfiled → event |
---|---|
priority: | undecided → low |
resolution: | → invalid |
status: | new → closed |
Changed November 19, 2012 08:26PM UTC by comment:2
If this is the case, it is incorrectly documented in the API documentation ( http://api.jquery.com/trigger/) (emphasis mine):
"The event object is always passed as the first parameter to an event handler, but if additional parameters are specified during a .trigger() call, these parameters will be passed along to the handler as well. To pass more than one parameter, use an array as shown here. As of jQuery 1.6.2, a single parameter can be passed without using an array."
The functionality you describe does not work as intended, as a single param still requires an array to make it work. Here's a fiddle proving this: http://jsfiddle.net/edelman/vg68j/
Changed November 19, 2012 08:39PM UTC by comment:3
The docs are wrong here. It's never been a good idea to pass something other than an honest JavaScript Array
, although it works for simple values like numbers. The problem with passing a jQuery object is that it looks array-like to makeArray, but it's no Array.
Issue created here: https://github.com/jquery/api.jquery.com/issues/178
additional parameters should be passed with an array.
But in this instance, it will be triggered in the context of #elt anyway.