#13130 closed bug (notabug)
data attributes not updated after appendTo
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | git |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Example: If you have a div with a data-mykey and you move this div using appendTo and then change the data attribute, there is unexpected behaviour.
Query the element directly and it reports the new value for the data attribute. As Expected.
Search the document for items with the new value for the data attribute and you will find none. Expected: you should find the div.
Search the document for items with the old value for the data attribute and you will find it. Expected: you should not find this element by its old attribute value.
JsFiddle: http://jsfiddle.net/analogNerd/3N5zA/1/
Change History (7)
comment:1 Changed 11 years ago by
Resolution: | → notabug |
---|---|
Status: | new → closed |
comment:5 Changed 11 years ago by
Not a bug: it's a specific design choice for the sake of performance and compatibility with jQuery's original jQuery.fn.data() which predates HTML5 custom data-* attrs. If you need to set custom data-* attrs, use the attr() method.
comment:6 Changed 11 years ago by
Feel free to update the documentation to make mention of this bug then. The documentation and the way it functions are not consistent.
comment:7 Changed 11 years ago by
Feel free to READ the documentation: http://api.jquery.com/data/#data-html5
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).
That is correct behavior and documented. The
.data()
method only reads data attributes once, and never sets data attributes. Use.attr()
if you are trying to set data attributes rather than the internal.data()
cache.