Skip to main content

Bug Tracker

Side navigation

#11746 closed bug (invalid)

Opened May 10, 2012 08:51AM UTC

Closed May 10, 2012 09:20AM UTC

Last modified August 22, 2012 01:19PM UTC

$().data() return undefined if name contains uppercase

Reported by: quaff Owned by:
Priority: low Milestone: None
Component: data Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Attachments (0)
Change History (5)

Changed May 10, 2012 09:20AM UTC by sindresorhus comment:1

component: unfileddata
priority: undecidedlow
resolution: → invalid
status: newclosed

That's because it doesn't find the data-attribute. Data-attributes are automatically lowercased by the browser.

HTML5 spec:

All attributes on HTML elements in HTML documents get ASCII-lowercased automatically

Changed May 11, 2012 01:22AM UTC by quaff comment:2

should jquery auto lowercase and keep correspondence with html5 spec?

Changed May 11, 2012 01:32AM UTC by dmethvin comment:3

_comment0: Nope, if you want mixed case you use the `-` character. Please read these, and followup with a forum post if needed: \ \ http://www.learningjquery.com/2011/09/using-jquerys-data-apis \ \ http://api.jquery.com/data/ \ 1336699956960003

Nope, if you want mixed case you use the "-" character. Please read these, and followup with a forum post if needed:

http://www.learningjquery.com/2011/09/using-jquerys-data-apis

http://api.jquery.com/data/

Changed August 22, 2012 12:07PM UTC by verheyen.koen@gmail.com comment:4

Would be nice if this was explained as a note in the docs so we know where to start looking.

Changed August 22, 2012 01:19PM UTC by dmethvin comment:5

The linked article about data APIs goes into plenty of detail, and says this:

Rule: When accessing data taken from data-* attributes, and especially when accessing the data object directly, use the W3C camelCasing conventions.

In any documentation there will be a tradeoff between describing every detail in every situation on every API where it can arise versus making the documentation readable and comprehensible.