<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width,
initial-scale=1">
<style>
body {
padding: 25px;
background-color: white;
color: black;
font-size: 25px;
}
.dark-mode {
background-color: black;
color: white;
}
</style>
</head>
<body>
<h2>Hello World</h2>
<p>Happy code</p>
<button onclick="myFunction()" id="button">night mode</button>
<script>
function myFunction() {
var element = document.body;
var button = document.getElementById("button");
let value = button.value;
if(value == "dark"){
button.value ="light";
button.innerHTML = "night mode";
}else{
button.value ="dark";
button.innerHTML = "day mode";
}
element.classList.toggle("dark-mode");
}
</script>
</body>
</html>
Get Answers For Free
Most questions answered within 1 hours.