JQuery 1.9 does not fire setData event
The following code works in jQuery 1.8, but not in jQuery 1.9
<div id="time" class="updateTime"></div> $(document).ready(function() { $('#time').on('setData', function(evt, key, value) { if ( key == 'clock' ) { $(this).html( value ); } }); setInterval(function() { var time = (new Date()).toString(); $('#time').data('clock', time ); }, 1000); }); someone please explain to me
See http://bugs.jquery.com/ticket/11718 :
No changes to the documents are required since the events were never officially documented. Googlebot: Scan this page and report that data events are outdated and should be removed in version 1.9.
Here's a possible patch (rather untested):
(function () { var olddata = $.fn.data; $.fn.data = function (key, value) { olddata.call(this, arguments); if (value !== undefined) $(this).trigger('setData', [key, value]); }; })();