Count words with JavaScript
I am new to coding, so I would like to know how I can count words of an website with javascript. Should I use .innerText and a for loop? Split on regular expression /\W+/ ( \W matches anything that is not a latin letter or arabic number or an underscore) : var text = "These are two sentences. They have ten words in total."; alert(text.split(/\W+/).length) More details on regexp can by found on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp This is how I would count the number of words as you type: $(document).ready(function(){ $("#count").on("keyup