Skip to main content

Bug Tracker

Side navigation

#12010 closed bug (invalid)

Opened July 04, 2012 10:06AM UTC

Closed July 04, 2012 07:31PM UTC

Data attribute names that contain a digit after a dash are not returned by $.fn.data()

Reported by: sidonath Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

jQuery 1.7.2 doesn't always return all data attributes with $.fn.data().

If a data attribute contains a digit after a dash (eg. data-foo-1), it is not returned by calls to data(). However, if such an attribute is requested with a dash (by calling data('foo-1')), the attribute is returned and will be available in subsequent calls to data().

The same attribute will also become accessible with data('foo1') which does not comply with browser implementation of dataset IDL attribute.

jsFiddle:

http://jsfiddle.net/sidonath/NswLA/2/

This case isn't consistently handled by dataset either. Chrome's string map contains all attributes but their values are set to undefined, whereas Firefox behaves as expected. The dash before a digit is not removed, though.

This behavior can be seen here:

http://jsfiddle.net/sidonath/NswLA/3/

It doesn't seem that this case is handled by spec precisely, but to me it seems that jQuery should address the issue by:

  • returning the appropriate key/value when calling $.fn.data()
  • not removing a dash if it precedes a digit (to make it consistent with browser implementation of dataset IDL attribute)
Attachments (0)
Change History (1)

Changed July 04, 2012 07:31PM UTC by rwaldron comment:1

_comment0: Numbers aren't valid in data-* attributes \ \ http://jsfiddle.net/rwaldron/2ahav/1341430446030748
resolution: → invalid
status: newclosed

Numbers aren't valid in data-* attribute names

http://jsfiddle.net/rwaldron/2ahav/