I have the following code:
alert($embellishment.data("embellishmentId"));
alert($embellishment.attr("data-embellishmentId"));
The first alert returns undefined
, whereas the second alert returns an integer, 3
.
I'm using jQuery version 1.7.2 (data
was added with version 1.4 I believe)
Why is this? Should I be using data()
at all if its not returning the right values?
OK. I found the problem by interpreting jQuery docs.
When you write:
it is handled by jQuery as compound attribute:
So, to solve the problem you can use lower case in the data key otherwise it just addresses the different attribute.