Bug Tracker


Ticket #8986 (closed bug: worksforme)

Opened 3 years ago

Last modified 3 years ago

element.data() returns undefined for given key!

Reported by: zeljko Owned by:
Priority: low Milestone: 1.next
Component: data Version: git
Keywords: Cc:
Blocking: Blocked by:





Function .data() returns undefined for given key (see fiddle). With jQuery ver <= 1.5.2 everything works as expected.

Change History

comment:1 Changed 3 years ago by dmethvin

Yes, that's working correctly and we did fix a bug in 1.6 that alters the behavior. See this test case for clarification:  http://jsfiddle.net/ZeSpD/1/

Here is the relevant W3C spec:  http://www.w3.org/TR/html5/elements.html#embedding-custom-non-visible-data-with-the-data-attributes

So "testkey" matches data-testkey, data-TESTKEY, data-testKey, etc. On the other hand, "testKey" matches data-test-key, data-test-Key, etc.

I'm leaving the ticket open for now to see if there are significant regressions reported.

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

comment:2 Changed 3 years ago by zeljko

Thanks. All clear now. It's best to avoid camel case data attributes in html.

comment:3 Changed 3 years ago by addyosmani

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

Closing as the original reporter is now clear on the actual behavior in 1.6. As we regularly monitor tickets which are re-opened or have new comments posted, should regressions be posted on this ticket we can re-open the ticket on reviewing, if they are valid.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.


Add a comment

Modify Ticket

as closed

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.