3 ms·
Wow, so agreed, accessing the DOM each time data() is called would be slower. There is a bigger problem though, they have created a situation where a person wou
by voidfiles 15y ago
Wow, so agreed, accessing the DOM each time data() is called would be slower. There is a bigger problem though, they have created a situation where a person would reasonably think that it works in a certain way, but it doesn't work that way at all.
This is the first place I have seen this behavior documented. Luckily, I have not ran into problems because of the weird behavior, but this could clearly cause a developer some confusion.
- dmethvin 15y agoIf by "they" you mean the W3C then yes I agree. :) The reason I wrote the post was because people see the `.data()` API in jQuery, which existed before HTML5, and think it has something to do with `data-` attributes. Indeed, we made it import them, but there isn't a good reason to keep them "in sync" -- and many reasons not to do that. I think all of behavior has been documented for some time, it's just spread across two or three different pages at http://api.jquery.com http://api.jquery.com. Also, the blog post is emphasized to draw the attention of people who are trying to misuse it to manipulate HTML5 `data-` attributes.
- voidfiles 15y agoWhen I say they, I mean the jQuery team, or whomever made the decisions to make the data api work that way. Clearly if someone was carefull in reading how the data api interacted with the data-* attributes they would see what was going on. The blog post is helpful in pointing out what jQuery actually does. I am just not sure in a cursory look at the api it would click in someones mind that it worked like that.