#10113 closed bug (wontfix)
Set internal null flag for data-attrs that are removed
Reported by: | Rick Waldron | Owned by: | Rick Waldron |
---|---|---|---|
Priority: | blocker | Milestone: | 1.7 |
Component: | data | Version: | 1.6.2 |
Keywords: | Cc: | cowboy | |
Blocked by: | Blocking: |
Description
Instead of brute removal (as seen in my 10026), Ben Alman has suggested (and I agree) that removal should not actually touch the DOM (if possible), but instead keep an internal flag that notes that this data-attr has been removed - this state should be reflected in the object returned by calling .fn.data()
Change History (9)
comment:1 Changed 12 years ago by
Component: | unfiled → data |
---|---|
Milestone: | None → 1.6.3 |
Owner: | set to Rick Waldron |
Priority: | undecided → blocker |
Status: | new → assigned |
comment:2 Changed 12 years ago by
comment:3 Changed 12 years ago by
Further tests, thanks to Ben Alman http://jsfiddle.net/rwaldron/cAcgZ/
comment:4 Changed 12 years ago by
Blocking: | 10026 added |
---|
comment:5 Changed 12 years ago by
Milestone: | 1.6.3 → 1.7 |
---|
comment:6 Changed 12 years ago by
Blocking: | 10026 removed |
---|
comment:7 Changed 12 years ago by
Cc: | cowboy added |
---|
Adding some kind of "been there done that" flag for this one special case seems like overkill. Perhaps the easiest solution is to document that if there is no property by that name in the internal data cache, we go out to look for data-
attributes. If you don't want it to re-query the data-
attribute, set the name to a value like null
or undefined
instead of using .removeData()
. Does that sound reasonable?
comment:8 Changed 12 years ago by
Keywords: | needsdocs added |
---|---|
Resolution: | → wontfix |
Status: | assigned → closed |
OK, I'm closing this with the needsdocs tag.
jQuery.fn.data("name") will attempt to find a data-
item again if you use .removeData("name"), so set it to null
or undefined
instead if you don't want that behavior.
Yeah.. if you don't set an internal flag but instead change the attribute on
$.fn.removeData
then the behavior of$.fn.data(key, value)
NOT changing the attr would be somewhat inconsistent. And you don't want to make that consistent by writing data to data attributes for 2 reasons.Anyways, I made an example fiddle. http://jsfiddle.net/cowboy/5GCgT/
Using
data-
attributes as declarative HTML that can be used by jQuery only to pre-populate$.fn.data(key)
makes sense. And the$.fn.data
and$.fn.removeData
methods should never change or modify the underlying attribute.