If you try to change a data attribute value with data()
method you don\'t get the same result as attr(data-key, data-value)
method.
For examp
.data() is used to store data in an object, but as of the "release" of HTML5, it can also access data-* attributes on elements.
However, it can not change these, as it is primarily used for storing data in objects etc, not physically on elements.
Therefore attr() is the only way to change a value of an attribute on an element, such as data-* attributes.
See: