Some weeks ago I received a customer request to add a character counter to a textarea field and I made it using “classic” Javascript. Now that I’m learning jQuery and have some spare time, I tryed to transform my custom function to a jQuery plugin.
This is my first attempt to build a jQuery plugin and maybe there’s already another plugin that does the same thing but it have been a really nice exercise.
This plugin will give you the method setCounter([maxLength]). If you call it on a textarea field you will get a counter that gets updated every time the user write a character.
The maxLength parameter is not mandatory so if it’s undefined you will get a simple character counter like this:
while if you pass an integer to the method the user won’t be able to write a number of character greater than maxLength and you will get a counter like this: