Reacting to Inputs

  • HTML elements can reference a function
  • onclick, onmouseover, onkeypress, etc.
  • The function needs to be defined somewhere
<p id="detonate-paragraph">Detonate</p>
<button onclick="detonate()">Don't click me!</button>
function detonate() {
    const paragraph = document.querySelector("#detonate-paragraph");
    paragraph.innerText = "Boom"
}

11 / 12