Skip to main content

Bug Tracker

Side navigation

#9124 closed bug (fixed)

Opened May 05, 2011 02:15PM UTC

Closed May 10, 2011 03:56PM UTC

Last modified July 12, 2011 02:24PM UTC

Changes to $.data illogical in certain case

Reported by: antti.kumpulainen@crasman.fi Owned by: dmethvin
Priority: blocker Milestone: 1.6.1
Component: data Version: 1.6
Keywords: Cc:
Blocked by: Blocking:
Description

This applies to all browsers and version 1.6 only.

I have a test case to reproduce the error.

I'm expecting that if I use .data('foo-bar') I get the data from 'foo-bar' or 'fooBar', but NOT "randomly".

Currently if .data('foo-bar', 'something') is called, after that .data('foo-bar') returns something even if fooBar has a value.

There are two solutions:

a) Do not return camel cased version with .data('foo-bar').

b) When setting .data('foo-bar', 'something'), set the camel cased version and not the actual 'foo-bar'.

Attachments (0)
Change History (4)

Changed May 05, 2011 02:41PM UTC by dmethvin comment:1

component: unfileddata
milestone: 1.next1.6.1
owner: → dmethvin
priority: undecidedblocker
status: newassigned

Agreed, as we discussed on IRC. It seemed like using the camel-cased name consistently would be the best approach. Thanks!

Changed May 10, 2011 03:56PM UTC by John Resig comment:2

resolution: → fixed
status: assignedclosed

Make sure that data properties with hyphens are always accessed/set using camelCase. Fixes #9124.

Changeset: a5e407cafb9d398b5bf2f209ad0e8a42691bf391

Changed July 12, 2011 11:29AM UTC by pscassidy@hotmail.com comment:3

I think this is counter-intuitive behaviour. Why would a user who has set a data property with "foo-bar" expect that the *only* way they can retrieve it is via "foobar".

The problem is that "foo-bar" is an illegal name in js - hence the HTML 5 spec on hyphens in data attributes.

If data is to follow the HTML 5 spec on js dataset access a better (consistent) solution would be to make hyphenated names illegal in data.

Changed July 12, 2011 02:24PM UTC by rwaldron comment:4

There is a pull request pending to allow access via hyphenated and camel cased property keys