Skip to content

Instantly share code, notes, and snippets.

@eldhosejoys
Last active December 16, 2019 06:36
Show Gist options
  • Save eldhosejoys/f86fd34ce9912e00ed204af542710eaa to your computer and use it in GitHub Desktop.
Save eldhosejoys/f86fd34ce9912e00ed204af542710eaa to your computer and use it in GitHub Desktop.
count the characters in the textarea using jquery
<center>
<textarea maxlength="100"></textarea>
<div id="charNum" class="text-light"></div></center>
<script>
// character counting
$('textarea').on("input", function(){
var maxlength = $(this).attr("maxlength");
var currentLength = $(this).val().length;
if( currentLength >= maxlength ){
$('#charNum').text(' You have reached the character limit');
}else{
$('#charNum').text(maxlength - currentLength + " characters left");
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment