Currently, I have this neat feature on my website where there's a button that toggles the image/background color - kind of like a dark mode switch. The background change is working fine, but I'm encountering some challenges with organizing the images properly. Here's what I have in terms of code:
function myFunction() {
var element = document.body;
element.classList.toggle("dark-mode")
}
function changeImage() {
var image = document.getElementById('myImage');
if(image.src.match("https://drive.google.com/uc?export=view&id=1zv8IxOU6cHccEanlwTnFmx9HWNQR9AA4")) {
image.src = "https://drive.google.com/uc?export=view&id=1H8ZfWPnLQ1dgKIo7geyyzlkAeh_QHrIa";
} else {
image.src = "https://drive.google.com/uc?export=view&id=1H8ZfWPnLQ1dgKIo7geyyzlkAeh_QHrIa";
}
}
.title {
font-size: 50px;
text-align: center;
background-color: #C1C1C1;
border-radius: 20px;
font-family: arial;
color: #00486B;
}
.img {
background: coral;
width: 500px;
padding: 30px;
margin-left: auto;
margin-right: auto;
display: block;
}
.body {
padding: 25px;
background-color: white;
color: black;
font-size: 25px;
}
.dark-mode {
background-color: black;
color: white;
}
.dark-mode .title {
color: yellow;
background-color: navy;
}
.dark-mode .img {
background-color: teal;
}
.main {
text-align: center;
font-size; 50px; border-radius: 20px;
font-family: arial;
color: #00486B;
}
<!doctype html>
<html>
<head>
<title>Java</title>
</head>
<body class="main">
<h1 class="title">TOGGLE DISPLAY</h1> <img src="https://drive.google.com/uc?export=view&id=1zv8IxOU6cHccEanlwTnFmx9HWNQR9AA4" class="img" id="myImage">
<br>
<button onclick="myFunction(); changeImage();" value="Change">CLICK</button>
</body>
</html>