Skip to main content

Bug Tracker

Side navigation

#10113 closed bug (wontfix)

Opened August 22, 2011 06:12PM UTC

Closed September 23, 2011 12:01AM UTC

Last modified December 11, 2011 09:28PM UTC

Set internal null flag for data-attrs that are removed

Reported by: rwaldron Owned by: rwaldron
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()

Attachments (0)
Change History (9)

Changed August 22, 2011 06:13PM UTC by rwaldron comment:1

component: unfileddata
milestone: None1.6.3
owner: → rwaldron
priority: undecidedblocker
status: newassigned

Changed August 22, 2011 06:21PM UTC by cowboy comment:2

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.

1. It's gonna be a lot slower to change the DOM every time you set data.

2. How can you store complex data like functions and regexes in a data attribute string?

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.

Changed August 22, 2011 06:58PM UTC by rwaldron comment:3

Further tests, thanks to Ben Alman http://jsfiddle.net/rwaldron/cAcgZ/

Changed August 22, 2011 07:04PM UTC by timmywil comment:4

blocking: → 10026

Changed August 25, 2011 06:05PM UTC by rwaldron comment:5

milestone: 1.6.31.7

Changed September 22, 2011 03:35AM UTC by rwaldron comment:6

blocking: 10026

Changed September 22, 2011 03:03PM UTC by dmethvin comment:7

cc: → cowboy

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?

Changed September 23, 2011 12:01AM UTC by dmethvin comment:8

keywords: → needsdocs
resolution: → wontfix
status: assignedclosed

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.

Changed December 11, 2011 09:28PM UTC by addyosmani comment:9

keywords: needsdocs

Docs updated.