Skip to content

Commit

Permalink
use input event listener for word counter example closes #51 (#80)
Browse files Browse the repository at this point in the history
* use input event listener for word counter example closes #51

* use template literals instead of string concatination
  • Loading branch information
MiB-1 authored Oct 29, 2024
1 parent d8f4090 commit 2e9fbac
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions word-count-web-component/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ class WordCount extends HTMLParagraphElement {
shadow.appendChild(text);

// Update count when element content changes
setInterval(function() {
const count = `Words: ${countWords(wcParent)}`;
text.textContent = count;
}, 200);
this.parentNode.addEventListener('input', () => {
text.textContent = `Words: ${countWords(wcParent)}`;
});
}
}

Expand Down

0 comments on commit 2e9fbac

Please sign in to comment.