5

I user jQuery 1.6.1 and browse is Chrome 11

I put some data in DIV, like this:

<div id="user" data-user-id="68029454802354176"></div>

and try to use .data() to fetch the userId

console.log($('#user').data('userId'));

I must get 68029454802354176, but it just return 68029454802354180

Why does it change my number?

4
  • do you have multiple elements with the id user? Commented May 20, 2011 at 4:13
  • Getting the same problem here Commented May 20, 2011 at 4:15
  • 1
    You've exceeded the max integer value do var a = 68029454802354176; in your browser Commented May 20, 2011 at 4:20
  • Same thing happened to me, when I had uniqid() uid there: data-uid="51e0888381259" - data() thought it is float and gave me Infinity Commented Jul 12, 2013 at 23:42

1 Answer 1

6

i dont think this has any thing to do with jquery more how javascript handels big numbers

its to bad data returns a number and not a string in this case

  $("#user").attr("data-user-id")

will get you a correct string at lest

if you put 68029454802354176 in the chrome console it gives you 68029454802354180 back

Sign up to request clarification or add additional context in comments.

2 Comments

@Drew yes, I think the number is exceeded. I find a link here:link Finally, I use .attr() to get the value, but sadly can't use data() to get all values. I don't know why can't data() get string value. Thanks guys help.
I would think this is a bug in data(). It's good that you can use attr(), you can also go the non jQuery route and pull it via HTML5 dataset() or HTML4 getAttribute() (probably called internally in attr(), but that's a complicated beast when I was looking on github). Here's a sample jsfiddle.net/8zcdu/1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.