Skip to main content

Bug Tracker

Side navigation

#15150 closed bug (notabug)

Opened June 16, 2014 02:42PM UTC

Closed June 16, 2014 02:44PM UTC

.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)
Attachments (0)
Change History (1)

Changed June 16, 2014 02:44PM UTC by dmethvin comment:1

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/