JSFiddle - React, Tailwind, and code Playground
HTML
<textarea class="txtQuestion"></textarea>
CSS
.error{
border: 1px solid red;
}
JavaScript
$(document).on("paste keydown", ".txtQuestion", function (e) {
var $this = $(this);
var max = 10;
setTimeout(function () {
var text = $this.val();
if (text.length >= max) {
e.preventDefault();
$this.addClass("error");
$this.val(text.substring(0, max));
} else {
$this.removeClass("error");
}
}, 100);
});