Last active
October 19, 2021 13:01
-
-
Save fieldoffice/abe7840124bcd45992f16f41fbf3edad to your computer and use it in GitHub Desktop.
Text Area Character Count
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
<textarea id="js-message" rows="4" maxlength="300"></textarea> | |
<div id="js-counter" class="message__counter">0 / 300</div> | |
<script> | |
// Character count | |
var message = document.getElementById('js-message'); | |
var counter = document.getElementById('js-counter'); | |
message.addEventListener('input', function (e) { | |
var target = e.target; | |
var maxLength = target.getAttribute('maxlength'); | |
var currentLength = target.value.length; | |
counter.innerText = currentLength + ' / ' + maxLength; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment