- Published on 23rd Aug 2017
This simple jQuery function can be used to trigger a callback everytime user stops typing. Just apply this to any text input fields such as textarea to see it in action.
(function($) {
$.fn.donetyping = function(callback){
var _this = $(this);
var x_timer;
_this.keyup(function (){
clearTimeout(x_timer);
x_timer = setTimeout(clear_timer, 1000);
});
function clear_timer(){
clearTimeout(x_timer);
callback.call(_this);
}
}
})(jQuery);
Usage :
$('textarea').donetyping(function(callback){
//your code goes here.
});