addEventListener: Coding lesson for kids
In “addEventListener”, children learn about const button = document.querySelector("#myBtn");; button.addEventListener("click", sayHi);; <button onclick="sayHi()">.
const button = document.querySelector("#myBtn");: Gets the button element from the page using its CSS selector — gives you a JavaScript reference to the actual element before you can listen for events on it.
button.addEventListener("click", sayHi);: The MODERN way to react to a click — names the element variable, the event, and the function to run.
<button onclick="sayHi()">: The older inline way — works, but mixes HTML and JavaScript together in one line.
This lesson is part of JavaScript in Coding at Pearls Valley Academy — What makes a webpage actually do something.
Each lesson starts with a short narrated, animated explanation, then hands-on practice. A wrong answer gets a gentle hint, never a penalty, and children earn stars and pearls as they go.