Created
July 9, 2020 04:09
-
-
Save gpDA/70c771d4b49e0a437148a80e69262d7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const wordCountElement = document.createElement('p'); | |
| wordCountElement.className = 'wordCount'; | |
| wordCountElement.innerHTML = 'Word Count: <strong id="blogWordCount">0</strong>'; | |
| document.body.appendChild(wordCountElement); | |
| const blogObserver = new EventObserver(); | |
| blogObserver.subscribe((text) => { | |
| const blogCount = document.getElementById('blogWordCount'); | |
| blogCount.textContent = getWordCount(text); | |
| }); | |
| const blogPost = document.getElementById('blogPost'); | |
| blogPost.addEventListener('keyup', () => blogObserver.broadcast(blogPost.value)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment