This was automatic, up to version 1.8.3 (determined by the source search for 'changeData').
However, it is written so that "changeData" is triggered if you do:
$element.data('key', 'newValue');
but not if you pass an object, for example:
$element.data({ 'key': 'newValue' });
Edited source excerpts to illustrate this:
jQuery.fn.extend({ data: function( key, value ) { // Gets all values if ( key === undefined ) { // expurgated } // Sets multiple values if ( typeof key === "object" ) { return this.each(function() { jQuery.data( this, key ); }); } return jQuery.access( this, function( value ) { if ( value === undefined ) { // expurgated } parts[1] = value; this.each(function() { var self = jQuery( this ); self.triggerHandler( "setData" + part, parts ); jQuery.data( this, key, value ); self.triggerHandler( "changeData" + part, parts ); }); }, } });
I'm not quite sure what jQuery.access does, but it seems to me (and testing confirmed) that the event only fires if you pass the second argument to newValue.
source share