;(function(jQuery){ jQuery.fn.clearTextLimit = function() { return this.each(function() { this.onkeydown = this.onkeyup = null; }); }; jQuery.fn.textLimit = function( limit , callback ) { if ( typeof callback !== 'function' ) var callback = function() {}; return this.each(function() { this.limit = limit; this.callback = callback; this.onkeydown = this.onkeyup = function() { this.value = this.value.substr(0,this.limit); this.reached = this.limit - this.value.length; this.reached = ( this.reached == 0 ) ? true : false; return this.callback( this.value.length, this.limit, this.reached ); } }); }; })(jQuery); jQuery('textarea').textLimit(100,function( length, limit ){ jQuery(this).next().text( limit - length ); });