Comment

Anthony

Actually the main difference is that data() is a way to store data for an element. This data is a JS variable. Which means reading from it and writing to it is faster cause it doesn't live in the DOM.

attr() on the other hand is a way to access attributes on nodes.

And it happens that data() will go check if the correspondent data-attribute exists when initialising the value.