Last active
August 29, 2015 14:00
-
-
Save ricardodsanchez/11245192 to your computer and use it in GitHub Desktop.
Count the number of words in a text editor, text box or text area and display total number of words as you type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('#editor').keyup(function () { | |
| typewatch(function () { | |
| // executed only 500 ms after the last keyup event. | |
| var words = $('#editor').html().toString().split(' '); | |
| // get number of words | |
| // add the value of words.length to a label, or other html element for displaying purposes as shown below | |
| $('.word-count').text(words.length); | |
| }, 500); | |
| }); | |
| var typewatch = (function () { | |
| var timer = 0; | |
| return function (callback, ms) { | |
| clearTimeout(timer); | |
| timer = setTimeout(callback, ms); | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment