Skip to main content

Bug Tracker

Side navigation

#14385 closed bug (notabug)

Opened September 24, 2013 03:46PM UTC

Closed September 24, 2013 04:06PM UTC

The data() method returns String values for custom data-* attributes which contain Number values

Reported by: jquery-bug@81008302.de Owned by:
Priority: undecided Milestone: None
Component: data Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:
Description

The data() method of jQuery returns String values for custom data-* attributes which contain Number values (containing trailing zeroes): http://jsfiddle.net/3A5tp/ (see console or html output).

Tested with the latest jQuery versions 1.x and 2.x in the most recent versions of Chrome and Firefox.

Greets

Attachments (0)
Change History (1)

Changed September 24, 2013 04:06PM UTC by gibson042 comment:1

component: unfileddata
resolution: → notabug
status: newclosed

This is by design:

A value is only converted to a number if doing so doesn't change the value's representation. For example, "1E02" and "100.000" are equivalent as numbers (numeric value 100) but converting them would alter their representation so they are left as strings. The string value "100" is converted to the number 100.

You can use parseFloat or numeric cast (e.g., +( $el.data("safe") )) to convert values yourself.