Welcome to the 12th Easy jQuery Tutorial, part of EasyProgramming.net. In the Easy JavaScript series, we learned about how to count characters in a text area, I want to show you this example in jQuery but instead of characters, we'll count words. This is a question that I've gotten a couple times and I think it's a great topic to cover because you can use this knowledge in any programming language, not just JavaScript.
You can find the Easy JS tutorial at the following link: Counting Characters in JS.
We'll be using the keyup jQuery event for this example:
$('textarea').on('keyup', function(){ var count = $('textarea').val().trim().split(' '); });
We're using a lot of what we learned in the past, including the on event method, the keyup event, selectors, input methods, and two different string methods (trim and split).
See the tutorial video below for a better understanding of how this is accomplished.
I hope you enjoyed this tutorial! Please feel free to ask questions below or just leave your comments.
To fork the fiddle and follow along: https://jsfiddle.net/easyjs/boxn9p1j/
Remember to checkout the Resources section below for associated downloadable content, JSFiddle links, and other resources. Watch the video and follow along!