Side navigation
#13110 closed bug (notabug)
Opened December 23, 2012 10:12AM UTC
Closed December 23, 2012 01:59PM UTC
.data() not working properly as HTML5 element.dataset does
Reported by: | alberto.delatorre@gmail.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | git |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
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:
$("div").attr("data-user","John");
Then the $("div").data() is not affected, but the $("div").get(0).dataset is updated:
{color: "black", id:"1", user:"John"}
Attachments (0)
Change History (2)
Changed December 23, 2012 10:25AM UTC by comment:1
Changed December 23, 2012 01:59PM UTC by comment:2
resolution: | → notabug |
---|---|
status: | new → closed |
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.
JSFiddle example: http://jsfiddle.net/qWpbm/