Exercise Set 6

Exercise 1 of 6

Add a click event listener to the third button.

HTML

<button id="button1">Button 1</button>
<button id="button2">Button 2</button>
<button id="button3">Button 3</button>
<p id="buttonTextParagraph"></p>

JavaScript

var button1 = document.getElementById("button1");
var button2 = document.getElementById("button2");
var button3 = document.getElementById("button3");
var buttonTextParagraph = document.getElementById("buttonTextParagraph");

button1.addEventListener("click", showButtonText);
button2.addEventListener("click", showButtonText);
// your code will appear here

function showButtonText() {
    buttonTextParagraph.innerHTML = this.innerHTML;
}

You must be signed in to type your code.

Last topic Next exercise