Is there a way to add a function to my current button?

Viewed 43

I am using JS and HTML. I have a button that displays the next section of html, but I wanted to add an additional function.

// Display Thanks Message
document.addEventListener('DOMContentLoaded', ()=>{
    document.getElementById("btn").addEventListener("click", addPerson function() {  
    q5.style.display = "none";
    end.style.display = "block";}
});

In this addPerson is the function I am trying to include. In this current code I keep getting syntax errors.

1 Answers

Call addPerson() inside the function.

// Display Thanks Message
document.addEventListener('DOMContentLoaded', () => {
  document.getElementById("btn").addEventListener("click", function() {
      addPerson();
      q5.style.display = "none";
      end.style.display = "block";
    }
  });
});

Related