The $.data
is used for storing information with respect to an element:
Store arbitrary data associated with the specified element. Returns
the value that was set.
On the other hand, attr
is used to manipulate attributes of an element.
From your question, you seem to store the data, you should use $.data
in that case.
data-* attributes are a feature of HTML5
Performance
.data() seems to be much more performance friendly according to this
I also find it cleaner since it’s not visible for everyone in page source.