jQuery Character Limit Counter

How to count number of characters in textarea using jQuery

(function ($) {
    $.fn.extend({
        limiter: function (minLimit, maxLimit, elem) {
            $(this).on("keydown keyup focus keypress", function (e) {
                setCount(this, elem, e);
            });

            function setCount(src, elem, e) {
                var chars = src.value.length;
                if (chars == maxLimit) {
                    //e.preventDefault();
                     elem.html(maxLimit - chars);
                    elem.addClass('maxLimit');
                    return false;
                     
                } else if (chars > maxLimit) {
                    src.value = src.value.substr(0, maxLimit);
                    chars = maxLimit;
                    elem.addClass('maxLimit');
                } else {
                    elem.removeClass('maxLimit');
                }
                if (chars < minLimit) {
                    elem.addClass('minLimit');
                } else {
                    elem.removeClass('minLimit');
                }
                elem.html(maxLimit - chars);
            }
            setCount($(this)[0], elem);
        }
    });
})(jQuery);

var elem = $("#chars");
$("#text").limiter(35, 100, elem);
jQuery Character Limit Counter jQuery Character Limit Counter Reviewed by Bhaumik Patel on 7:05 PM Rating: 5