4 ms·
Then what's the problem? You stored float 1.410 and got back float 1.41. They're equal. That's not jQuery, it's javascript: http://jsfiddle.net/kgp2H/1/ http:/
by unfletch 15y ago
Then what's the problem? You stored float 1.410 and got back float 1.41. They're equal. That's not jQuery, it's javascript: http://jsfiddle.net/kgp2H/1/ http://jsfiddle.net/kgp2H/1/
Edit, after the parent was edited to include the data attribute example:
You should update your post to clarify that you're talking about data attributes. That's a significant detail and shouldn't have been left out.
Now that you've clarified, jQuery does behave as you've stated, but it's not a bug. I can see how it could be unexpected behavior to some, but it's explicitly stated in the .data() documentation:
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.
http://api.jquery.com/data/#data2 http://api.jquery.com/data/#data2
- stickfigure 15y agoThat may be the documented behavior, but that doesn't make it the correct behavior. The problem is that we have a typeless language applying arbitrary type detection to strings... and it will invariably guess wrong. A string of "1.410" is not the same as a float of 1.41. Running "1.410" full-circle through data() corrupts the input string. When you have data that has been entered by a user, you can't guarantee that it's not something that will happen to autoconvert. This behavior is totally broken and should never be used. It will work 99.95% of the time, then fail in bizarre ways when a user types in something magic. These are the worst bugs in the world to hunt down. This really shouldn't be in jquery.