#5532 closed bug (worksforme)
jQuery.trigger doesn't pass data argument when its object with length property
Reported by: | mikz | Owned by: | brandon |
---|---|---|---|
Priority: | major | Milestone: | 1.4 |
Component: | event | Version: | 1.3.2 |
Keywords: | makeArray, length | Cc: | |
Blocked by: | Blocking: |
Description
jQuery.trigger (and probably more functions) doesn't pass data when it's Object with length property. jQuery.makeArray doesn't recognize this object and tries to make array from it, which returns undefined.
Test: $("body").bind("custom", function(event, data) { console.log(data); }); $("body").trigger("custom", {length: "fails"}); $("body").trigger("custom", {test: "passes"});
Change History (3)
comment:1 Changed 13 years ago by
comment:2 Changed 13 years ago by
Mikz, read the docs to trigger. The data has to be an array and is passed along as arguments to the event handler.
$("body").trigger("custom", [ {test: "passes"}, 'more', 'args' ]);
custom = function(e, one, two, three) {
one === object one.test === passes two === more three === args
}
comment:3 Changed 13 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Yep, if you pass an Array as documented it works fine.
workaround: $("body").trigger("custom", [ {test: "passes"} ]);