Skip to content

Instantly share code, notes, and snippets.

@timhberry
Created January 8, 2023 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timhberry/ea2281d7163fff7c9662f6cd78e434c7 to your computer and use it in GitHub Desktop.
Save timhberry/ea2281d7163fff7c9662f6cd78e434c7 to your computer and use it in GitHub Desktop.
$('textarea').keyup(function() {
var characterCount = $(this).val().length,
current = $('#current'),
maximum = $('#maximum'),
theCount = $('#the-count');
current.text(characterCount);
/*This isn't entirely necessary, just playin around*/
if (characterCount < 70) {
current.css('color', '#666');
}
if (characterCount > 70 && characterCount < 90) {
current.css('color', '#6d5555');
}
if (characterCount > 90 && characterCount < 100) {
current.css('color', '#793535');
}
if (characterCount > 100 && characterCount < 120) {
current.css('color', '#841c1c');
}
if (characterCount > 120 && characterCount < 139) {
current.css('color', '#8f0001');
}
if (characterCount >= 140) {
maximum.css('color', '#8f0001');
current.css('color', '#8f0001');
theCount.css('font-weight','bold');
} else {
maximum.css('color','#666');
theCount.css('font-weight','normal');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment