$.event.special.inputchange = {
setup: function() {
var self = this, val;
$.data(this, ‘timer’, window.setInterval(function() {
val = self.value;
if ( $.data( self, ‘cache’) != val ) {
$.data( self, ‘cache’, val );
$( self ).trigger( ‘inputchange’ );
}
}, 20));
},
teardown: function() {
window.clearInterval( $.data(this, ‘timer’) );
},
add: function() {
$.data(this, ‘cache’, this.value);
}
};

$(‘input’).on(‘inputchange’, function() {
$(‘p’).text(this.value);
});
$(“input”).keyup(function () {
$(‘h1’).text(this.value);
});

The difference between Keyup and the custom function inputchange is
the keyup function will not work while you will click on the cross x (which cames after you write something on the text box).

Ref- http://jsfiddle.net/LGAWY/

Advertisements