Bug Tracker

Ticket #11746 (closed bug: invalid)

Opened 3 years ago

Last modified 2 years ago

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

Reported by: quaff Owned by:
Priority: low Milestone: None
Component: data Version: 1.7.2
Keywords: Cc:
Blocking: Blocked by:

Change History

comment:1 Changed 3 years ago by sindresorhus

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to data

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

comment:2 Changed 3 years ago by quaff

should jquery auto lowercase and keep correspondence with html5 spec?

comment:3 Changed 3 years ago by dmethvin

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/

Last edited 3 years ago by dmethvin (previous) (diff)

comment:4 Changed 2 years ago by verheyen.koen@…

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

comment:5 Changed 2 years ago by dmethvin

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.

Note: See TracTickets for help on using tickets.