#8191 closed bug (worksforme)
removeData() does not remove data-* attribute
Reported by: | speednet | Owned by: | speednet |
---|---|---|---|
Priority: | low | Milestone: | 1.next |
Component: | data | Version: | 1.5 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
If you set a data value with a data-* attribute on an element, and then in JavaScript code you use .removeData() to remove it, the attribute does not get removed as it should. If you query .data() right after removeData(), it will continue to return the original value in the data-* attribute.
Change History (3)
comment:1 Changed 12 years ago by
Owner: | set to speednet |
---|---|
Priority: | undecided → low |
Status: | new → pending |
comment:2 Changed 12 years ago by
Component: | unfiled → data |
---|---|
Resolution: | → worksforme |
Status: | pending → closed |
I put together this live test case which shows everything is working as expected. The data that was set with .data()
is correctly removed.
I think there may be a slight misunderstanding on what .removeData()
does in the case of data-* attributes. The removeData() documentation reads:
The .removeData() method allows us to remove values that were previously set using .data().
and for data-* attributes reverts
to the value of the data attribute of the same name in the DOM
So .removeData()
is never going to "remove" the actual data-* HTML attribute, which it also isn't supposed to as the original value wasn't set by .data()
.
I included some more code in the test case which you can uncomment and play around with to get a better understanding of how .data()
, .removeData()
and data-* attributes play together.
comment:3 Changed 12 years ago by
Wow, I missed that one in the docs, thanks very much for the review and great explanation.
Thanks for submitting a ticket to the jQuery Bug Tracker. In order for us to assist you further, please provide a reduced test case on jsFiddle which reproduces the behavior you're experiencing. We'll evaluate the bug as soon as you've supplied this. Thanks!.