I have a textarea where contents need to be restricted by a word limit.
<textarea class="user_response"></textarea>
Here is the code I have so far. I could change the color of whole text but could not find a way to change color after the word limit.
$(".user_response").on('keyup', function() {
var words = this.value.match(/\S+/g).length;
if (words > gWordLimit) {
$(this).css("color","red");
} else
$(this).css("color","black");
});
The desired outcome: If the word limit is 2, after the second word, the color of excess characters should be highlighted as red, per say.