Bug Tracker

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#13815 closed bug (fixed)

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

Reported by: gregoryb@… Owned by: Rick Waldron
Priority: high Milestone: 2.0.1
Component: data Version: 2.0.0
Keywords: Cc:
Blocked by: Blocking:

Description

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.

http://jsfiddle.net/aEDKF/7/

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.

Change History (4)

comment:1 Changed 4 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: newassigned

comment:2 Changed 4 years ago by Rick Waldron

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

comment:3 Changed 4 years ago by Corey Frang

Resolution: fixed
Status: assignedclosed

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

Changeset: 55e319aa52eb828a3a4c2298aa75b6d15cfa06f8

comment:4 Changed 4 years ago by gnarf

Component: unfileddata
Milestone: None2.0.1
Priority: undecidedhigh
Note: See TracTickets for help on using tickets.