Skip to content

Instantly share code, notes, and snippets.

@apertureless
Created January 13, 2015 11:34
Show Gist options
  • Save apertureless/0301877347ecb6f99048 to your computer and use it in GitHub Desktop.
Save apertureless/0301877347ecb6f99048 to your computer and use it in GitHub Desktop.
Remaining characters counter for textareas
/*
Display remaining characters in a textarea.
*/
(function($) {
// Get every teatarea
$( 'textarea[maxlength]' ).each(function(){
// Add listener
$(this).on('input propertychange', function() {
// Parse maxlength attribute
var max = parseInt($( this ).attr( 'maxlength' ));
// Display remaining characters
$(this).parent().find('.remaining').html(max - $(this).val().length);
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment