Skip to content

jQuery.fn.data() and data-* attribute name restrictions #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rwaldron opened this issue Nov 6, 2013 · 6 comments
Open

jQuery.fn.data() and data-* attribute name restrictions #383

rwaldron opened this issue Nov 6, 2013 · 6 comments
Assignees

Comments

@rwaldron
Copy link
Member

rwaldron commented Nov 6, 2013

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>
@ithcy
Copy link

ithcy commented Nov 6, 2013

@rwaldron
Copy link
Member Author

rwaldron commented Nov 6, 2013

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

@ithcy
Copy link

ithcy commented Nov 6, 2013

Understood. I was just asking for clarification. It seemed to be "will not work except when it does work" based on my stupid test :)

@rwaldron
Copy link
Member Author

rwaldron commented Nov 7, 2013

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.

@malsup
Copy link

malsup commented Dec 18, 2013

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.

@timmywil
Copy link
Member

timmywil commented May 4, 2015

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.

@AurelioDeRosa AurelioDeRosa self-assigned this Oct 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants