Side navigation
#13130 closed bug (notabug)
Opened December 28, 2012 03:16PM UTC
Closed December 28, 2012 03:22PM UTC
Last modified February 20, 2013 05:23PM UTC
data attributes not updated after appendTo
Reported by: | astoute@daemons.com | 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.
Attachments (0)
Change History (7)
Changed December 28, 2012 03:22PM UTC by comment:1
resolution: | → notabug |
---|---|
status: | new → closed |
Changed February 20, 2013 04:48PM UTC by comment:4
This is a bug. Not sure how you can consider it not a bug.
Changed February 20, 2013 05:01PM UTC by comment:5
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.
Changed February 20, 2013 05:04PM UTC by comment:6
Feel free to update the documentation to make mention of this bug then. The documentation and the way it functions are not consistent.
Changed February 20, 2013 05:23PM UTC by comment:7
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.