The Bitter Pill

50,000 watts of power … Got my radio on

Simple jQuery word count

I had a need today for a simple textarea word count script, so whipped this up using jQuery. It ain’t fancy, but it works:

$(document).ready(function(){
  $(\"#text\").keyup(function() {
     $('#count').html($('#text').val().split(/\b[\s,\.-:;]*/).length);
  });
});

I’ll leave it to you to remember you have to have jQuery in place, and sort out the IDs on the textarea and where you’d like the word count to appear.

Leave a Reply