I will create a javascript remaining character counter for an HTML textarea. But my code is not working. How can I fix this.
$(document).ready(function(){
var length = 0;
var maximumCharacters = 160;
$('#description').keyup(function(){
length = this.value.length;
if(length > maximumCharacters){
return false;
} else if (length > 0){
$("#remaining-characters").html("Remaining characters: " + (maximumCharacters-length));
} else {
$("#remaining-characters").html("Remaining characters: " + maximumCharacters);
}
})
})
<div class="row mb-3">
<label for="description" class="col-sm-2 col-form-label label">Description</label>
<div class="col-sm-10">
<textarea class="form-control form textarea" id="description" name="description" maxlength="160"></textarea><span id="remaining-characters"></span>
</div>
</div>