Why don’t changes to jQuery $.fn.data() update the corresponding html 5 data-* attributes?

Normally, there’s not a need for roundtripping .data()‘s if you’re consistent in using .data() to access/set/modify data on DOM elements. For that reason, it makes sense to avoid the performance overhead of accessing the DOM for every .data() set/modify operation (.data() stores its values in jQuery.cache internally).

If you want to force the roundtrip behavior yourself, you could subscribe to the “setData” or “changeData” events and then push the .data() update in those events through to the corresponding DOM element via .attr().

Leave a Comment