Bug Tracker

Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#9066 closed bug (invalid)

$(element).data() breaks with camel case "data-" attributes

Reported by: anonymous Owned by:
Priority: low Milestone: 1.next
Component: data Version: 1.6
Keywords: Cc:
Blocked by: Blocking:


It appears that the changes to $(element).data() have broken some existing functionality.

If I have an element, <input id="foo" data-someThing="bar">, and try to access the data via $('foo').data('someThing') it's now returning -undefined- instead of "bar". However, $('foo').data('something') does return "bar".

I can't tell if this is a bug or not from the documentation, but it appears wrong to me. I'm assuming this broke/changed with the other changes to data regarding hyphens, but to me it shouldn't be modifying case of the data attribute when it does not contain any hyphens. Or, at a minimum, the documentation needs to be clear that this will happen.

Change History (10)

comment:1 Changed 8 years ago by anonymous

Here is a fiddle demonstrating the issue...


comment:2 Changed 8 years ago by Rick Waldron

Component: unfileddata
Priority: undecidedlow
Resolution: invalid
Status: newclosed

According to the latest Element data-* attributes spec, all html attributes are lowercased automatically. In fact, capitol letters are forbidden:

"contains no characters in the range U+0041 to U+005A (LATIN CAPITAL LETTER A to LATIN CAPITAL LETTER Z)"


Last edited 8 years ago by Rick Waldron (previous) (diff)

comment:3 Changed 8 years ago by timmywil

To be clear, we made this change in 1.6 to match the spec. To retrieve the data, use .data('something') and it will match. http://jsfiddle.net/timmywil/b2wgk/

comment:4 Changed 8 years ago by anonymous

This still seems wrong though considering if instead I use <input id="foo" data-some-thing="bar"> then this, $('#foo').data('someThing') is now valid.

This seems terribly inconsistent...

comment:5 Changed 8 years ago by anonymous

At a minimum http://api.jquery.com/data/#data2 should be updated to include these rules. For someone new to jQuery this would be extremely confusing.

comment:6 Changed 8 years ago by Rick Waldron

Keywords: needsdocs added

Adding needsdocs tag

comment:7 Changed 8 years ago by dmethvin

Keywords: needsdocs removed

Updated docs.

comment:8 Changed 8 years ago by dmethvin

To be clear, the blog entry for 1.6 mentions this under Breaking Changes. And the reason it broke is because we fixed a bug in order to be in conformance with the standard. So it's unfortunate, and we're sorry, but it's the right move. Trying to make old code work would cause a bigger mess.

comment:9 Changed 8 years ago by anonymous

Fair enough, I did see the entry in the blog but wanted to make sure some note of it also made it out to the documentation.

Thanks everyone!

comment:10 Changed 7 years ago by keith.kirkhope@…

where in the http://api.jquery.com/data/ page does it say that <div data-roleOne="page" /> is only retrievable by calling $('div').data('roleone') ? If it does then its not clear and the "HTML 5 data- Attributes" should have an example showing it.

Note: See TracTickets for help on using tickets.