JSFiddle - React, Tailwind, and code Playground
HTML
<div class="box">
<textarea name="" id="text"></textarea>
<div class="word-counter">0/100</div>
</div>
CSS
.box {
width:500px;
border: 1px solid red;
position:relative;
display:table;
}
textarea {
width:500px;
height:80px;
padding-bottom: 20px;
}
.word-counter {
position:absolute;
bottom: 0;
right:0;
}
JavaScript
$('#text').keydown(function(e){
var code=e.keyCode;
var length=$(this).val().split(' ').length;
if(length<=100)
{
$('.word-counter').text(length+'/100');
}
else
{
if(code!=37&&code!=38&&code!=39&&40&&code!=8&&code!=46)
{
return false;
}
}
});