Goal
Modify the previous script to also display a live word count.
Project
You’ve written 0 words and 0 characters.
View Source
(function() {
let elText = document.querySelector( "#text" );
let elCharacterCount = document.querySelector( "#character-count" );
let elWordCount = document.querySelector( "#word-count" );
elText.addEventListener( "input", e =>
{
elCharacterCount.innerText = e.target.value.length;
elWordCount.innerText = e.target.value.trim()
.split( /\s+/g )
.length;
});
})();
Projects
- Toggle Password Visibility
- Toggle Multiple Password Fields
- Toggle Passwords in Multiple Forms
- Character Count
- Character and Word Count
- Announcing the Count
- Random Ron
- Random Ron Without Duplicates
- New York Times Top Stories
- New York Times Multiple Categories
- Sanitizing the NYT API Data
- Monster Shuffle