Skip to main content

Bug Tracker

Side navigation

#10106 closed bug (duplicate)

Opened August 22, 2011 11:26AM UTC

Closed August 22, 2011 01:18PM UTC

Last modified August 22, 2011 01:18PM UTC

.data() as string

Reported by: Aske Owned by:
Priority: low Milestone: None
Component: data Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:

When i store a value like "001" into the data attribute and retrieve it with .data() i get "1" returned. This should be "001" and not parsed as an int.

Example here:

Attachments (0)
Change History (3)

Changed August 22, 2011 12:00PM UTC by addyosmani comment:1

component: unfileddata
priority: undecidedlow
status: newopen

Confirmed. I believe we're using parseFloat(n) as opposed to parseInt(n), but it's essentially causing the same issue regardless. One possible workaround for now would be storing 001 as a single-quoted string within your data-value, however this isn't ideal:

Changed August 22, 2011 01:18PM UTC by timmywil comment:2

resolution: → duplicate
status: openclosed

This is expected behavior and a feature of the .data() method. It is explained in the docs:

"Every attempt is made to convert the string to a JavaScript value (this includes booleans, numbers, objects, arrays, and null) otherwise it is left as a string. To retrieve the value's attribute as a string without any attempt to convert it, use the attr() method."

Changed August 22, 2011 01:18PM UTC by timmywil comment:3

Duplicate of #10042.