Intro to Events
Events describe actions such as a click or an input change. Register a listener rather than writing JavaScript inside an HTML attribute.
Where to run this
This example changes a document. Open it in the HTML playground, then select Run code. It runs inside a separate preview.
A practical example
<button id="book" type="button">Check places</button>
<p id="message"></p>
<script>
document.getElementById("book").addEventListener("click", () => {
document.getElementById("message").textContent = "Three places remain.";
});
</script>
What happens
Clicking the button reveals the message.