jQuery textCounting Plugin

The jQuery textCounting plugin will count the number of characters or 'words' (blocks of characters separated by one or more spaces) in a <textarea> every time a character is typed in the <textarea>, and will display either the number of words or characters in the <textarea> or how many words or characters can still be typed before reaching the set limit.

The default behavior of the plugin is to display the number of characters left before reaching the limit (a character countdown). You can use the plugin for this purpose "as is" (without specifying or changing any settings) if you follow these conventions in your coding:

Here's an example of a <textarea> and a <span> element that fit the convention:

<textarea id="comments" maxTextLength="1000" rows="4" cols="60"></textarea>
<p>Characters left: <span id="commentsDown"></span></p>

Because the element ids and the maxTextLength value is specific to each <textarea>, you can use a single call of the plugin to display a countdown for all your <textarea> elements:

<script language="javascript">
  $(document).ready(function()
    $(":input[type=textarea]").textCounting();
   });
</script>

If the default plugin behavior is not suitable, the plugin has a number of settings that can be changed. Here are a few examples:

The GitHub repo contains a heavily-documented version of the plugin (where you can read more details about all of the settings and how to change them) for use in development, as well as a minified version for use in production.

Below is a demonstration of the plugin in action. You can use the "View Source" option of your browser to inspect this page and see how the demo is coded.





Characters left: 0



Characters: 0 | Characters left: 0



Words: 0 | Words left: 0