JSFiddle - React, Tailwind, and code Playground
by Jordan Marechal
HTML
<textarea id="myWordsToCount" rows="5" cols="60">
<span id ="words">0</span> words
JavaScript
"use strict";
console.clear();
var words = document.getElementById("words");
var myTextareaElement = document.getElementById("myWordsToCount");
myTextareaElement.value = ' ';
myTextareaElement.onkeyup = function() {
function myWordsToCount(str) {
var words = myTextareaElement.value.split(' ');
myWordsToCount.innerText = words.length;
return str.split(' ').length;
}
console.log(myTextareaElement);
}