admin管理员组

文章数量:1420073

I have the following div <div data-item-id="0234"> and when I try to access the data with $element.data("itemId") jQuery converts it to int and now i get 234 instead of "0234". Is there any way i can get the actual data "0234" ?

I have the following div <div data-item-id="0234"> and when I try to access the data with $element.data("itemId") jQuery converts it to int and now i get 234 instead of "0234". Is there any way i can get the actual data "0234" ?

Share Improve this question edited Jun 14, 2012 at 6:27 Engineer 48.9k12 gold badges90 silver badges92 bronze badges asked Jun 11, 2012 at 16:14 danielsdaniels 19.3k34 gold badges109 silver badges174 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 5

Simply use .attr instead ($element.attr('data-item-id');). The docs themselves suggest this.

Try this:

$element.attr("data-item-id")

Using attr: http://jsbin./ipuhah/

$(selector).attr("data-item-id");

本文标签: javascriptjQuery data() type conversion issueStack Overflow