#10320 closed bug (invalid)
pass a jquery object as trigger data
Reported by: | 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.
Change History (3)
comment:1 Changed 12 years ago by
Component: | unfiled → event |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
comment:2 Changed 10 years ago by
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/
comment:3 Changed 10 years ago by
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.