JS WEB APISChapter 7 · JS Web APIs
Events and Listeners
Pages respond to people through events. element.addEventListener("click", handler) runs handler every time the element is clicked. The handler receives an event object with details such as event.target, the element that was clicked. After you press Run, click the buttons in the page below: your handlers run for real. You can also trigger a click from code with element.click().
Worked example
How it reads
- The handler does not run when you add it, only when the event happens
launcheslives outside the handler, so it remembers the count between clicksbutton.click()fires a real click event from code

Cloud tip: Pass the function itself,
addEventListener("click", launch), not launch(). The parentheses would call it once, immediately.

