Count Clicks
HTML
Start Counting
JavaScript
window. = ;
Notes
-
This example shows how to keep track of values (aka maintaining state).
-
The
window.ClickCounterclass defines a private field variable named#counterto keep track of the number of clicks. -
Each time the button is used the this.#counter += 1; lines adds one to the #coutner.
-
Then, the
el. ... line displays update the button with the new value.