Reputation: 13141
Given an element like this <a data-test="10E6">
jQuery interprets the value as an integer in scientific notaion rather than a string as intended when I do elem.data('test')
Given that this is happening in a fairly large application I'm exploring my options for changing this behavior without having to switch to using elem.attr('data-test')
everywhere that this may happen.
Since jQuery uses $.isNaN internally before trying to parse the value as a float I could override isNaN adding the regex ^[E\d]+$
like so:
$.isNaN = function( obj ) {
return obj == null || !$.rdigit.test( obj ) || /E/.test( obj ) || isNaN( obj );
}
or override the much more complex $.data
Does anyone have a better plan?
Upvotes: 0
Views: 551
Reputation: 41256
According to the documentation of .data()
itself, the jQuery developers tell you to use .attr()
to retrieve the value without coercing it. I'd imagine overriding the internals that jQuery is using would be a more detrimental problem than simply switching to the appropriate method.
Upvotes: 3