JSFiddle - React, Tailwind, and code Playground

by Simplybj

HTML

Comments
<br />
<textarea col="100" rows="10" id="textAreaComment">

</textarea>
<br />
<span class="wordCounter">
  0
</span> /1000 (including spaces)

<br /> Comments
<br />
<textarea col="100" rows="10" id="textAreaComment1">

</textarea>
<br />
<span class="wordCounter1">
  0
</span> /1000 (including spaces)

JavaScript

$('#textAreaComment').on('keyup', function(index, value) {

  var count = $('#textAreaComment').val().trim().length;
  $('.wordCounter').text(count);
});

$('#textAreaComment1').on('keyup', function(index, value) {

  var count = $('#textAreaComment1').val().trim().length;
  $('#textAreaComment1').val(
    $('#textAreaComment1').val().replace(/\s\s\s\s/g, "....")
  )
  $('.wordCounter1').text(count);
});