jQuery TypingEnd Event

Ever wanted to fire an event when a user stops typing into an input or textarea? Here is a quick jQuery plugin to do just that:


        typingEnd: function(callback, timeout){
            callback = callback || null;
            timeout = timeout || 500;

            return this.each(function() {
                var $t = $(this),
                    elapse_timeout = null;
                    $t.bind('typingEnd', callback);

                            elapse_timeout = setTimeout(function(){
                            }, timeout);
                        }); // end keyup
                else $t.trigger('typingEnd');
            }); // end each
        } // end typingEnd
    }); // end extend


Once you include this snippet you can attach events like the following

// pass in the callback function

// if the typingEnd functionality is already bound to the element you can use bind
$myInput.bind('typingEnd', anotherCallback);

It will check if the user has pressed any keys within the given timeout. If not the event is fired.