Starlit Daily

📚 › JavaScript: make pages do things

12. Events in the browser

JavaScript reacts to events such as clicks. addEventListener('click', function) runs your code when the element is clicked. document.querySelector finds an element by its CSS selector.

This is how pages respond to visitors.

Show example

const btn = document.querySelector("#go");
btn.addEventListener("click", () => alert("Clicked"));

✍️ Your turn

Print the text Event ready. Use console.log only, the runner has no page.

← Back to course