We have this 'strange' situation where some product codes, for example 11E6, which are stored in data attributes (ex data-prodcode) are getting converted to 11000000, when retrieved inside jquery click function. Something like this:
<a data-prodcode="11E6">click</a>
var code = $(this).data('prodcode');
console.log(code); --> 11000000
Any advice on how to avoid this behavior or what may cause it?
From the documentation :
You may use
attr
in order to avoid automatic parsing :To be more precise : this shouldn't happen. And in fact it doesn't happen in last versions. Here's the code of current's jQuery (the most interesting part is the comment) :
And it works in jQuery 1.8 and 1.9 : it doesn't convert the string to a number if a back conversion doesn't produce the same string. But it didn't work in jQuery 1.7.