Skip to main content

Bug Tracker

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.

JsFiddle: http://jsfiddle.net/analogNerd/3N5zA/1/

Attachments (0)
Change History (7)

Changed December 28, 2012 03:22PM UTC by dmethvin comment:1

resolution: → notabug
status: newclosed

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.

Changed February 12, 2013 08:28PM UTC by rwaldron comment:2

#13440 is a duplicate of this ticket.

Changed February 20, 2013 12:40PM UTC by gibson042 comment:3

#13482 is a duplicate of this ticket.

Changed February 20, 2013 04:48PM UTC by anonymous comment:4

This is a bug. Not sure how you can consider it not a bug.

Changed February 20, 2013 05:01PM UTC by rwaldron 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 anonymous 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 rwaldron 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).