Side navigation
#7210 closed bug (wontfix)
Opened October 16, 2010 01:53PM UTC
Closed October 22, 2010 05:41AM UTC
Last modified October 22, 2010 11:01AM UTC
.removeData doesn't remove data when data-* attributes are used
Reported by: | cowboy | Owned by: | |
---|---|---|---|
Priority: | high | Milestone: | 1.4.4 |
Component: | data | Version: | 1.4.3 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Test case here: http://jsfiddle.net/cowboy/s8XgA/ (also inline, at the bottom of this ticket)
One approach would be to set a flag in jQuery's data system once a data- attribute has been accessed to tell .data to never again try to fetch it from the attribute. The other approach of removing the data- attribute from the element after being accessed could be problematic, in case the element were to be cloned afterwards.
var div = $('div'); div.data( 'baz', 789 ); console.log( div.data( 'foo' ) ); // 123 console.log( div.data( 'bar' ).a ); // "456" console.log( div.data( 'baz' ) ); // 789 div.removeData( 'foo' ); div.removeData( 'bar' ); div.removeData( 'baz' ); console.log( div.data( 'foo' ) ); // 123 console.log( div.data( 'bar' ).a ); // "456" console.log( div.data( 'baz' ) ); // undefined
Attachments (0)
Change History (9)
Changed October 16, 2010 01:54PM UTC by comment:1
_comment0: | FWIW, I told Paul about this issue well before it was integrated into core. → 1287241088866024 |
---|
Changed October 16, 2010 02:22PM UTC by comment:2
component: | unfiled → data |
---|---|
priority: | undecided → low |
status: | new → open |
I can confirm this issue is as-described by cowboy. Opening for additional comments and a patch.
Changed October 16, 2010 02:26PM UTC by comment:3
resolution: | → duplicate |
---|---|
status: | open → closed |
As this issue has been already flagged in #7209, I'm moving the discussion on this particular bug to there as we've already isolated one of the areas of the core causing these issues.
Changed October 16, 2010 02:28PM UTC by comment:5
Both tickets seem to be related, in that they deal with .removeData
, but I think they're separate issues.
Changed October 16, 2010 03:12PM UTC by comment:6
resolution: | duplicate |
---|---|
status: | closed → reopened |
On second glances you're correct. The issues are related but are in fact different in nature. Re-opening.
Changed October 19, 2010 06:45AM UTC by comment:7
priority: | low → high |
---|---|
status: | reopened → open |
Changed October 22, 2010 05:41AM UTC by comment:8
resolution: | → wontfix |
---|---|
status: | open → closed |
This behavior is correct given the nature of .data() and data- attributes. Data properties that you set are just a light layer sitting on top of the data- attributes themselves. The value of the data- attribute is only pulled in to the data structure once (the first time it's accessed) and then left as-is (unless the user explicitly uses .attr() to manipulate it). Thus the original value with always be there even if you change .data() or call .removeData(). This is all as designed: .data() and data- are similar to .style and stylesheets (you can change .style all you want but the underlying stylesheets will always remain intact). This also has the side effect of being fast.
Changed October 22, 2010 11:01AM UTC by comment:9
_comment0: | Not sure who will see this comment, but in the future, any time a reasonable issue is closed as "wontfix" the docs should probably be checked to see if they could be made more clear. In this example, the <a href="http://api.jquery.com/removeData/">API docs for .removeData</a> fail to mention this behavior anywhere. \ → 1287745308865750 |
---|---|
_comment1: | Not sure who will see this comment, but in the future, any time a reasonable issue is closed as "wontfix" the docs should probably be checked to see if they could be made more clear. In this example, the [http://api.jquery.com/removeData/ API docs for .removeData] fail to mention this behavior anywhere. \ → 1287745459782749 |
Not sure who will see this comment, but in the future, any time an issue is closed as "wontfix" the docs should probably be checked to see if they could be made more clear. In this example, the API docs for .removeData fail to mention this behavior anywhere.
(FWIW, I raised this issue well before the code was integrated into core)