.data() Optionally Update HTML5 Attribute
As it is now, the
.data() function retrieves the data from HTML5
data-* attributes when the page loads. When data is set using the function, the DOM attribute is not updated, for efficiency. If you want the attribute to be updated as well, you have to then pass the same data to
.attr() .
.data( key, value, updateAttr )
What I am proposing is an optional third argument (second in the
.data( obj ) signature),
updateAttr . It would be a Boolean (defaulting to
false ). When
true ,
.data() would also update the corresponding
data-* attribute.
In a web page I'm working on, a
data-* element is used for both JavaScript and for styling with CSS, which is what prompted this idea.