Created
January 13, 2015 11:34
-
-
Save apertureless/0301877347ecb6f99048 to your computer and use it in GitHub Desktop.
Remaining characters counter for textareas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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