Description
Description
When using the data() function, then jQuery will get the attribute value if it doesn't exist, and get the data and NOT attribute value if it doesn't exist.
Heres an example:
If you fire $("div").data("foo");, then it will return "house".
That makes you believe that the data("foo") function is linked to the data-foo attribute in the DOM.
So if you set it now like this: $("div").data("foo", "bike");
Now you think that the data-foo attribute value is "bike", haha, thats not the case, its still "house".
So now, to get the attribute data-foo, you need to write $("div").attr("data-foo");
And to get the foo data in the code that i set, then i need to go for $("div").data("foo").
That is EXTREMELY error prone, because there could be name classes between the
An example could be if you wanted to check if a key/value pair is undefined in the data(). But it is defined if the DOM object has the attribute and it is undefined if it doesn't have that attribute.
I figured it out when i was coding, and i expected something to be undefined, but it was defined because i had the same data-XXX attribute name as i had in the data("XXX") jQuery function. And then all the bug hell broke lose.
Is this a bug or a stupid intend? I think its very error-prone.