and when I try to access the data using $element.data(...">

Problem with jQuery data type conversion?

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

+4
source share
3 answers

Just use .attr instead of ( $element.attr('data-item-id'); ). The documents themselves suggest this.

+5
source

Try the following:

 $element.attr("data-item-id") 
+3
source

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

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

All Articles