JSFiddle - React, Tailwind, and code Playground

by Roy Howie

HTML

<p>Enter no more than 10 words:</p>
<textarea id="myText"></textarea>

CSS

textarea {
    width: 300px;
    height: 100px;     
}

JavaScript

var maxWords = 10;
$("#myText").keypress(function (event) {
    var text = $(this).val().split(" ");
    while (text.length > maxWords) {
        event.preventDefault();
        text.pop();
    }
    $(this).val(text.join(" "));
})