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: | marco@m-s-d.eu | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.10.2 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Hi!
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 http://jsfiddle.net/ZYz4A/.
Alternatively, I'd suggest placing something in the manual at http://api.jquery.com/data/ 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
Changed October 13, 2013 12:04PM UTC by comment:4
resolution: | → notabug |
---|---|
status: | new → closed |
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
Hi!
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 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.
Furthermore, data() and the data selector are not compatible with each other.
The behaviour described in http://visualstudiomagazine.com/articles/2013/02/01/working-with-html5.aspx does not work when mixing .attr() and .data() writes to the data storage; I updated the fiddle to http://jsfiddle.net/ZYz4A/1/.