Issue with jQuery data() treating string as number

This isn’t a case of “long int” really, the number you’re getting is the closest available representation as a floating-point number.

Anyway, you want the value as a string. Quote the jQuery docs for .data (emphasis mine):

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.

Leave a Comment