Bug Tracker

Modify

Ticket #13815 (closed bug: fixed)

Opened 12 months ago

Last modified 12 months ago

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

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

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

comment:1 Changed 12 months ago by rwaldron

  • Owner set to rwaldron
  • Status changed from new to assigned

comment:2 Changed 12 months ago by rwaldron

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 12 months ago by Corey Frang

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: 55e319aa52eb828a3a4c2298aa75b6d15cfa06f8

comment:4 Changed 12 months ago by gnarf

  • Priority changed from undecided to high
  • Component changed from unfiled to data
  • Milestone changed from None to 2.0.1

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.