Bug Tracker

Ticket #8986 (closed bug: worksforme)

Opened 4 years ago

Last modified 4 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:

Description

Fiddle:

 http://jsfiddle.net/ZeSpD/

Description:

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

Change History

comment:1 Changed 4 years ago by dmethvin

Yes, that's working correctly and we did fix a bug in 1.5.2 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.

Version 0, edited 4 years ago by dmethvin (next)

comment:2 Changed 4 years ago by zeljko

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

comment:3 Changed 4 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.

Note: See TracTickets for help on using tickets.