Skip to main content

Bug Tracker

Side navigation

#6734 closed bug (duplicate)

Opened June 28, 2010 01:48PM UTC

Closed October 03, 2010 07:08PM UTC

Overwritten binded events when use .data() with object

Reported by: Xelat Owned by:
Priority: undecided Milestone: 1.4.3
Component: data Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:
Description

jQuery method .data() returns object with properties "events" and "handle", which used as I understand for handling events. But when I use .data() with first parameter as object with key/values pairs, it overwrite existing data instead of adding that key/value pairs to data object.

Finally when handling events of that object, I have error in Firebug console "e is undefined".

For example:

$('td:first').click(someFunc).data({some_id: 11});

when click TD, will have error

Attachments (0)
Change History (4)

Changed June 28, 2010 01:56PM UTC by Xelat comment:1

Please, move ticket to jQuery 1.4.2 bugs list.

Changed October 03, 2010 06:10PM UTC by addyosmani comment:2

priority: → undecided
resolution: → invalid
status: newclosed

Your usage of .data() here appears to be incorrect. You're setting an object to be added to .data() on the event handler using .data(X) rather than .data(X,Y) for the key-value pairs.

I've written a number of tests here which you can review for correct usage where adding an object (or string value) in the way originally desired (that works). This all works fine using FireFox with Firebug for console output.

http://jsfiddle.net/2gRWE/

In particular I would direct you to review here where you can set

/*Store object as a part of the event handler*/

$("td:first").click(someFunc).data('myObject', {some_id: 11});

var test2 = $("td:first").click(someFunc).data('myObject');

console.log(test2);

Changed October 03, 2010 07:07PM UTC by dmethvin comment:3

resolution: invalid
status: closedreopened

Changed October 03, 2010 07:08PM UTC by dmethvin comment:4

resolution: → duplicate
status: reopenedclosed