-
Notifications
You must be signed in to change notification settings - Fork 0
/
toggle.js
29 lines (25 loc) · 939 Bytes
/
toggle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const heading = document.getElementById("myHeading");
const toggleColourButton = document.getElementById("toggleColourButton")
toggleColourButton.addEventListener("click", toggleColourClicked);
function toggleColourClicked() {
let buttonText = toggleColourButton.textContent;
if (buttonText === "Red") {
heading.classList.remove("red");
heading.classList.add("green");
toggleColourButton.textContent = "Green";
} else if (buttonText === "Green") {
heading.classList.remove("green");
heading.classList.add("blue");
toggleColourButton.textContent = "Blue";
} else if (buttonText === "Blue") {
heading.classList.remove("blue");
heading.classList.add("red");
toggleColourButton.textContent = "Red";
}
}
/**
* Next:
*
* Add a second toggle button that instead of changing colours,
* changes fonts.
*/