jQuery.fn.data() and data-* attribute name restrictions
http://bugs.jquery.com/ticket/14376
jQuery.fn.data() will not work data-* attributes in the very specific case where an attribute has been named with multiple words and any of the words after the first word (not including data-) begin with a digit.
Example:
<div data-foo-42></div>
However, these work just fine:
<div data-42></div>
<div data-foo42></div>
What do you mean by "will not work"? It appears to work fine here: http://jsbin.com/IzIKInET/1/edit?html,js,output
What I mean by "will not work" is "will not work". Yes, you're asking for the property specifically, that's fine, we'll make sure the docs reflect this; in the meantime, take a look at this: http://jsbin.com/aWaWegi/4/edit?html,js,console
Understood. I was just asking for clarification. It seemed to be "will not work except when it does work" based on my stupid test :)
It seemed to be "will not work except when it does work" based on my stupid test :)
Unfortunately, yes. This is a particularly frustrating and hairy bug. @gnarf and I would ultimately like to break backward compatibility in favor of HTML5 data-* compatibility, but no definite answer yet.
Backward compat is already broken.
$('<div data-mike-123="alsup"></div>').data('mike-123')
Works in 1.9, fails in 2.x.
I agree on the sentiment that it should track the dataset spec.
This will be fixed in 3.0. However, we should document that retrieving data with keys containing numbers after dashes may not return the expected result before jQuery 3.0 and that the dash will not be removed in this case in 3.0+, which will reflect the dataset spec.