Last active
December 16, 2019 06:36
-
-
Save eldhosejoys/f86fd34ce9912e00ed204af542710eaa to your computer and use it in GitHub Desktop.
count the characters in the textarea using jquery
This file contains hidden or 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
<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