I am learning the basics of JavaScript and seem to have run into a wall and just can not find the answer to figure out how to change the button text when clicked. So my JavaScript code runs to where when the button in html is clicked, then the background color of the site toggles night and day (in terms of mode). However I am trying to toggle the text in the button to change when clicked.
So when the background color is in day mode, the button says "Night Mode", then once clicked, I would want the button text to toggle to "Day Mode" to convert back to original state. Your help will be greatly appreciated!!
HTML:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<title>Button Shifter</title>
</head>
<body>
<h1>COLOR SHIFTER: Day/Night Mode</h1>
<p>Click the button to see some magic! Toggle between Day and Night mode! Give it a try!</p>
<br><br><br><br>
<button onclick="toggleTheme()" id="myButton" >Dark Mode</button>
<script src="Javascript.js"></script>
</body>
</html>
JavaScript:
function toggleTheme() {
document.body.classList.toggle('dark-mode');
element.classList.toggle("dark-mode");
var btn = document.getElementById("myButton");
if (btn.value == "Night Mode"){
btn.value = "Day Mode";
}else {
btn.value = "Night Mode";
}