Ticket #12010 (closed bug: invalid)
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: | ||
| Blocking: | Blocked by: |
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)
Change History
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Numbers aren't valid in data-* attribute names
http://jsfiddle.net/rwaldron/2ahav/