Bug Tracker

Opened 10 years ago

Closed 10 years ago

#13110 closed bug (notabug)

.data() not working properly as HTML5 element.dataset does

Reported by: [email protected] Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: git
Keywords: Cc:
Blocked by: Blocking:


If you have an element:

<div data-color="black" data-id="1">...</div>

The $("div").data() and $("div").get(0).dataset will return:

{color: "black", id:"1"}

If in js code we do:


Then the $("div").data() is not affected, but the $("div").get(0).dataset is updated:

{color: "black", id:"1", user:"John"}

Change History (2)

comment:1 Changed 10 years ago by anonymous

JSFiddle example: http://jsfiddle.net/qWpbm/

comment:2 Changed 10 years ago by dmethvin

Resolution: notabug
Status: newclosed

The data attributes map is only synchronized once, otherwise it would be extremely expensive to retrieve:

The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery). http://api.jquery.com/data/

Please read the docs and ask for help on the forum if it still isn't clear.

Note: See TracTickets for help on using tickets.