-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle-button.html
More file actions
46 lines (44 loc) · 1.03 KB
/
toggle-button.html
File metadata and controls
46 lines (44 loc) · 1.03 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
background-color: white;
color: black;
}
.dark {
background-color: black;
color: white;
}
#toggle {
border-radius: 5px;
background-color: yellow;
color: black;
box-shadow: inset;
height: 30px;
width: 70px;
}
</style>
</head>
<body>
<h2>toggle mode</h2>
<button id="toggle">Switch</button>
<!-- <script src="/javascript/dom5.js"></script> -->
<script>
let body = document.querySelector("body");
let button = document.querySelector("#toggle");
let heading = document.querySelector("h2");
button.addEventListener("click", () => {
body.classList.toggle("dark");
if(body.classList.contains("dark")) {
heading.innerText = "dark mode"
} else {
heading.innerText = "light mode"
}
});
</script>
</body>
</html>