Skip to main content

Bug Tracker

Side navigation

#13815 closed bug (fixed)

Opened April 23, 2013 09:44PM UTC

Closed April 24, 2013 09:10PM UTC

Last modified April 24, 2013 09:13PM UTC

Setting data property with data(object) produces different results than data(key, value)

Reported by: Owned by: rwaldron
Priority: high Milestone: 2.0.1
Component: data Version: 2.0.0
Keywords: Cc:
Blocked by: Blocking:

This might be a Bootstrap bug, but it showed up when I upgraded to jQuery 2.0.0 from 1.9.0. I'm filing a bug with Bootstrap as well.

I'm getting some weird behaviour when I set data properties by passing in an object instead of setting each data property individually. In my case the weirdness shows up when I'm toggling some button text using Bootstrap.

I set data properties on two buttons simultaneously:

$("#a, #b").data({"type": "foo"})

And then I let Bootstrap reset the button text on both buttons. When I then go to change one button individually it changes the other button even though I'm specifically getting the button by ID.

I don't see this behaviour when I set the data property using key/value instead of an object:

$("#a, #b").data("type", "foo")

In my jsFiddle I have both methods so you can test both of them. The 'object' method is commented out to start.

I don't see this behaviour in jQuery 1.9.x (Edge), just in the 2.0 branch.

Attachments (0)
Change History (4)

Changed April 23, 2013 09:49PM UTC by rwaldron comment:1

owner: → rwaldron
status: newassigned

Changed April 23, 2013 10:12PM UTC by rwaldron comment:2

The old behaviour makes sense and is actually what I was expecting when I re-wrote src/data... I was surprised when I discovered that freshly set data objects were being assigned and retaining references (according to the tests for src/event).

I have a feeling that something changed in test/unit/event when it was re-written for 2.0

Changed April 24, 2013 09:10PM UTC by Corey Frang comment:3

resolution: → fixed
status: assignedclosed

Fixes #13815: Ensure each element has its own private data object - Tests by @rwldrn

Changeset: 55e319aa52eb828a3a4c2298aa75b6d15cfa06f8

Changed April 24, 2013 09:13PM UTC by gnarf comment:4

component: unfileddata
milestone: None2.0.1
priority: undecidedhigh