Skip to main content

Bug Tracker

Side navigation

#14441 closed bug (notabug)

Opened October 13, 2013 02:25AM UTC

Closed October 13, 2013 12:04PM UTC

Last modified October 13, 2013 12:39PM UTC

jQuery .data method should return always fresh values

Reported by: Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:


As stated in the manual, the .data() method pulls in the HTML5 data- attributes only once per element.

However, this is bad from a debugging perspective - I would like to be able to do a $(el).attr("data-foo","bar") followed by either .data() or further .attr("data-foo","...") calls so that the current value of the data attribute is visible in the DOM inspector.

A quick testcase is at

Alternatively, I'd suggest placing something in the manual at which says how one can quickly see the data attribute values in the Inspectors of Chrome, IE and Firefox.

Attachments (0)
Change History (6)

Changed October 13, 2013 02:41AM UTC by comment:1

Furthermore, data() and the data selector are not compatible with each other.

The behaviour described in does not work when mixing .attr() and .data() writes to the data storage; I updated the fiddle to

Changed October 13, 2013 12:00PM UTC by dmethvin comment:2

#14443 is a duplicate of this ticket.

Changed October 13, 2013 12:00PM UTC by dmethvin comment:3

#14442 is a duplicate of this ticket.

Changed October 13, 2013 12:04PM UTC by dmethvin comment:4

resolution: → notabug
status: newclosed

The properties of .data() are intentionally not serialized to the element on its dataSet, for example they could be a function or complex constructed objects. We are not going to change the documented semantics of .data().

Changed October 13, 2013 12:10PM UTC by comment:5


Thanks for the answer (and I'm fine with not changing the semantics due to BC)... but how is one then supposed to filter by the data attribute? Not serializing it back definitely breaks the [data-key=value] selector, so I'm re-opening the issue if you don't mind.

Changed October 13, 2013 12:39PM UTC by dmethvin comment:6

Use .attr("data-xxxx") to set the data attribute, as described in the docs. There is no performant way to search the entire DOM for values set by .data() because it's not intended for those uses; use a class instead.