Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
$("textarea[maxlength]").each(function() { const max = $(this).attr("maxlength"); const $counter = $(`<small class="text-muted char-count">${max} remaining</small>`).insertAfter(this); $(this).on("input", function() { const left = max - this.value.length; $counter.text(`${left} remaining`).toggleClass("text-danger", left < 20); }); });
Result
Open