Bug Tracker

Opened 9 years ago

Closed 9 years ago

#15150 closed bug (notabug)

.data() doesn't convert '10.00' to number.

Reported by: gersonk Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.11.1
Keywords: Cc:
Blocked by: Blocking:

Description

<span id="a" data-value='10.00'>
<span id="b" data-value='10.01'>
  $("#a").data("value"); // returns "10.00" (string)
  $("#b").data("value"); // returns 10.01 (number)

Change History (1)

comment:1 Changed 9 years ago by dmethvin

Resolution: notabug
Status: newclosed

Every attempt is made to convert the string to a JavaScript value (this includes booleans, numbers, objects, arrays, and null). 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.

http://api.jquery.com/data/

Note: See TracTickets for help on using tickets.