This jQuery Word and character counter plug-in allows you to count characters or words, up or down. You can set a minimum or maximum goal for the counter to reach.
It will insert a div with an id of the name of the input area you are counting with a "_counter" suffix. For example, if the
input you want to count is called "countMe", the id of the div that keeps track of the count will be "countMe_counter".
Simple? You bet your ass it is.
| Name | Value | Description |
|---|---|---|
| type | char || word | Count characters or words by using 'char' or 'word' respectively. |
| count | down || up | Count up or down to or from your goal |
| goal | 140 || x || 'sky' |
The goal number. If you are counting down, the counter will start on this number. If however you are counting up, the counter will end on this number.
Sky's the limit! Setting the goal to the string |
| text | true || false | Set false if you only want the numbers to show and not the words (msg). |
| msg |
|
There are various defaults set based on the type, count conditions being used. You can also set your own message to be added after the counter.
If you want the message off, just set the text to false. |
The most basic way to use the counter is to simply call the counter() method on a jQuery object.
$("#default_usage").counter();
Start typing!
Bacon ipsum dolor sit amet beef short loin pork belly strip steak venison, pig bacon tenderloin ribeye ham hock pastrami fatback brisket meatloaf. Flank ribeye chicken ball tip, shoulder pastrami turkey.
Copy & paste the text to the right of the input box above inside the text area. You'll notice that the text gets cut off, not allowing you to paste or type any further.
If you want the numbers only Twitter feel, use the text option.
$("#default_usage_num_only").counter({
text: false
});
By default, this plugin will count characters. Also by default, it will count down. Lets see how counting up to ten will look:
$("#charUp").counter({
count: 'up',
goal: 10
});
Bacon ipsum dolor sit amet beef short loin pork belly strip steak venison, pig bacon tenderloin ribeye ham hock pastrami fatback brisket meatloaf. Flank ribeye chicken ball tip, shoulder pastrami turkey.
Since by default this plugin counts characters, you have to set the type option to wordlike so:
$("#wordDown").counter({
type: 'word',
goal: 20
});
New in 2.0!
After a user pastes more than the words allowed, the extra words will be removed.
Bacon ipsum dolor sit amet beef short loin pork belly strip steak venison, pig bacon tenderloin ribeye ham hock pastrami fatback brisket meatloaf. Flank ribeye chicken ball tip, shoulder pastrami turkey.
Similarly, if you want to count words up, you would set the count option do up like so:
$("#wordUp").counter({
type: 'word',
goal: 20,
count: 'up'
});
Bacon ipsum dolor sit amet beef short loin pork belly strip steak venison, pig bacon tenderloin ribeye ham hock pastrami fatback brisket meatloaf. Flank ribeye chicken ball tip, shoulder pastrami turkey.
Let's say you don't like the default text appended to the coutner. Simple, just change it.
$("#custom_msg").counter({
msg: 'words left before you fall into a pit of emptiness.'
});
Sky is the limit! (Cheesy, I know.)
Setting the goal to the string 'sky' (with quotes) overrides the count to up and removes the default message. You can optionaly put your own custom message by using the msg option.
$("#keepCountingChar").counter({
goal: 'sky'
});
$("#keepCountingWord").counter({
goal: 'sky',
type : 'word',
msg : 'amazing words'
});
'Sky' string value to the goal option that enforces counting up without a limit.Questions, comments? Email webdevbx at gmail dot com
Thank you.
Word and character counter at plugins.jquery.com