04. Character Count


You've written 0 characters.

HTML

1
2
3
4
<label class="label" for="text">Enter your text below.</label>
<textarea class="textarea" id="text"></textarea>

<p>You've written <strong><span id="character-count">0</span> characters</strong>.</p>

JavaScript

1
2
3
4
5
6
7
8
9
10
/* As the user types or pastes text into the #text field, 
the #character-count content should get updated in real time
to display how many characters are in the field. */

let textArea = document.getElementById('text');
let letterCounter = document.getElementById('character-count');

textArea.addEventListener('input', function (e) {
letterCounter.textContent = e.target.value.length
})