Skip to content

Commit 69f27fb

Browse files
committed
added color change feature
1 parent 923bfd1 commit 69f27fb

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

‎Students/kamala/dom.html‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Color Change</title>
5+
<style>
6+
body {
7+
background-color: white;
8+
text-align: center;
9+
margin-top: 100px;
10+
}
11+
12+
button {
13+
padding: 10px 20px;
14+
font-size: 18px;
15+
background-color: blue;
16+
color: white;
17+
border: none;
18+
cursor: pointer;
19+
}
20+
</style>
21+
</head>
22+
23+
<body>
24+
25+
<button onclick="changeColor()">Click Me</button>
26+
27+
<script>
28+
// Colors list
29+
const bgColors = ["black", "red", "blue"];
30+
const btnColors = ["red", "black", "green"];
31+
32+
let index = 0;
33+
34+
function changeColor() {
35+
// Change background color
36+
document.body.style.backgroundColor = bgColors[index];
37+
38+
// Change button color
39+
const btn = document.querySelector("button");
40+
btn.style.backgroundColor = btnColors[index];
41+
42+
// Move to next color
43+
index++;
44+
45+
// Reset index when it reaches end
46+
if (index >= bgColors.length) {
47+
index = 0;
48+
}
49+
}
50+
</script>
51+
52+
</body>
53+
</html>

0 commit comments

Comments
 (0)