Bug Tracker

Opened 9 years ago

Closed 9 years ago

#7499 closed enhancement (invalid)

data() can only read Data Attribute objects in single quotes

Reported by: p_gasston@… Owned by:
Priority: undecided Milestone: 1.5
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

Description

When using data() to get objects from a Data Attribute, the attribute must be within single quotes:

<div data-example='{"foo":"bar"}'>

It's much more common to use double quotes for attributes, so the following should also be valid:

<div data-example="{'foo':'bar'}">

This is not currently recognized by jQuery.

Change History (2)

comment:1 in reply to:  description Changed 9 years ago by jitter

Replying to p_gasston@…:

so the following should also be valid: <div data-example="{'foo':'bar'}">

This isn't a jQuery bug. The reason this doesn't work is the value of data-example looks like JSON but actually is invalid. JSON requires you to use double quotes (check http://www.json.org/).

comment:2 Changed 9 years ago by dmethvin

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.