steveosoule
7/30/2015 - 1:49 AM

Textarea Maxlength Counter

Textarea Maxlength Counter

(function maxLength(){
	$('.js-maxlength').on('input', function(){
		var $textarea = $(this),
			maxLength = $textarea.attr('maxlength'),
			counterSelector = $textarea.data('maxlength-counter');

		$(counterSelector).text(maxLength - $textarea.val().length);
	});
})();
<textarea class="js-maxlength" data-maxlength-counter="#js-message-counter" maxlength="100"></textarea>
You have <strong id="js-message-counter" class="text-primary">100</strong> characters left.