#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: |
Description
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 12 years ago by
comment:2 Changed 12 years ago by
Component: | unfiled → data |
---|---|
Priority: | undecided → low |
Resolution: | → invalid |
Status: | new → closed |
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)"
comment:3 Changed 12 years ago by
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 12 years ago by
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 12 years ago by
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:8 Changed 12 years ago by
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 12 years ago by
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 11 years ago by
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.
Here is a fiddle demonstrating the issue...
http://jsfiddle.net/UvYdA/