I am trying to create a very simple form. My objective is to create two clickable buttons, each containing a question. When clicked, the DOM will output the answer below the each button. The tricky part is getting both buttons to respond with only one addEventListener
. Here is my code:
HTML:
<div id="wrapper">
<header>
<h1>Have you ever wondered...</h1>
</header>
<div>
<button id="myBtn">How many licks it takes to get to the center of a tootsie pop?</button>
<p id="first"></p>
<h3>Or what about...</h3>
<button id="myBtnTwo">How tall the Eiffel Tower is?</button>
<p id="second"></p>
</div>
</div>
JS:
document.getElementById("myBtn").addEventListener("click", function(){
document.getElementById("first").innerHTML= "Approximately 364 licks!";
});
document.getElementById("myBtnTwo").addEventListener("click", function(){
document.getElementById("second").innerHTML= "984 feet!";
});