addEventListener

  • You can "listen" for events in JavaScript like you can in HTML
  • Similar to adding an onclick event handler in HTML
<div class="my-panel">
    <header>Panel Title</header>
</div>
const myPanelHeader = document.querySelector(".my-panel header");
myPanel.addEventListener("click", changeColor);

function changeColor() {
    myPanelHeader.style.color = "red"
}

2 / 21