Description
Referring to the simpler data function (http://api.jquery.com/data/) The behavior of the .data() function when setting data should be described more precisely, especially the difference between setting a html5 data attribute (properly) with .attr() and (not properly) with .data().
I was about to file a bug report with this sample: https://jsfiddle.net/wfh1ppxv/ when I found following this closed issue jquery/jquery#3158 it is intended behavior?
It is correct that the documentation does not say that calling .data("key", "value") will result in the html's DOM element data attribute set with data-key="value", but because of:
- the name of the function
- the following example to read the data
- the description for the read function "Return the value at the named data store for the first element in the jQuery collection, as set by data(name, value) or by an HTML5 data-* attribute."
- the references to the W3 specification for the dataset API
I find it very easy to think you could set the DOM data attribute with the .data() function. I suggest there should be a small note on the section for the set data function, pointing to .attr().