-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolors2.html
More file actions
24 lines (22 loc) · 800 Bytes
/
colors2.html
File metadata and controls
24 lines (22 loc) · 800 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<!DOCTYPE html>
<html>
<head>
<script>
document.addEventListener('DOMContentLoaded', () => {
// Have each button change the color of the heading
document.querySelectorAll('.color-change').forEach(button => {
button.onclick = () => {
document.querySelector('#hello').style.color = button.dataset.color;
};
});
});
</script>
<title>My Website</title>
</head>
<body>
<h1 id="hello">Hello!</h1>
<button class="color-change" data-color="red">Red</button>
<button class="color-change" data-color="blue">Blue</button>
<button class="color-change" data-color="green">Green</button>
</body>
</html>