Bug Tracker

Opened 9 years ago

Closed 9 years ago

#6556 closed bug (fixed)

.data(object) breaks event handling

Reported by: jaredjacobs Owned by:
Priority: undecided Milestone: 1.4.3
Component: event Version: 1.4.2
Keywords: data, event handler, handle Cc:
Blocked by: Blocking:

Description

Calling .data({...}) results in a JS exception in jQuery.event.handle whenever a previously bound event handler is fired.

The documentation for .data() says: "Until jQuery 1.4.2, jQuery itself used the .data() method to save information about events that have been bound to the element, using a data item named 'events'."

There is unfortunately still some code in jQuery 1.4.2 that assumes that there is data about event bindings stashed in .data("events"). For example, this line from jQuery.event.handle is the one I'm seeing blow up:

var events = jQuery.data(this, "events"), handlers = events[ event.type ];

A quick search for the JS string "events" turns up two other similar sites: one in liveHandler (non-fatal) and one in jQuery.event.special.live.remove (probably fatal).

Change History (5)

comment:1 Changed 9 years ago by jaredjacobs

Here's an example that triggers the problem. It was posted in the jQuery.data comments 3 months ago. http://api.jquery.com/data/#comment-30025031

$('<div>click me</div>').click( function(){alert('where?')} ).data( {key: 'val'} ).appendTo( 'body' );

comment:2 Changed 9 years ago by jaredjacobs

Workaround, of course, is to call .data(k1, v1).data(k2, v2)...

Last edited 9 years ago by jaredjacobs (previous) (diff)

comment:3 Changed 9 years ago by petersendidit

This seems to be fixed in 1.4.3

comment:4 Changed 9 years ago by jaredjacobs

agreed. thanks team!

comment:5 Changed 9 years ago by snover

Priority: undecided
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.