Skip to content

Instantly share code, notes, and snippets.

@gpDA
Created July 9, 2020 04:09
Show Gist options
  • Save gpDA/70c771d4b49e0a437148a80e69262d7a to your computer and use it in GitHub Desktop.
Save gpDA/70c771d4b49e0a437148a80e69262d7a to your computer and use it in GitHub Desktop.
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