JSFiddle - React, Tailwind, and code Playground
by EMIR MARQUES
HTML
<input type="text" id="test"/>
JavaScript
(function($){
$.fn.look = function(fn) {
return this.each(function() {
var self = this, oldVal = $(self).val();
$(this).data("watch_timer", setInterval(function() {
if ($(self).val() != oldVal) {
fn.call(self, oldVal, $(self).val());
oldVal = $(self).val();
}
}, 100));
return self;
});
};
})(jQuery);
$(function(){
$("#test").look(function(oldVal, newVal){
alert("Mudou! Valor antigo: " + oldVal + " novo valor: " + newVal);
});
});