I've been experimenting with toggling the background color of a button, similar to how changing the margin works. For some reason, the margin toggles correctly but the button's color doesn't.
<script>
let myBtn = document.querySelector("#menuBtn");
function toggleMargin() {
var Menubase = document.getElementById("list-menu-base");
if (Menubase.style.marginTop === "0px") {
Menubase.style.marginTop = "-250px";
} else {
Menubase.style.marginTop = "0px";
}
}
myBtn.onclick = toggleMargin;
// The function above works, but the one below does not//
function changeColor() {
var Menubase = document.getElementById("menuBtn");
if (Menubase.style.backgroundColor === "red") {
Menubase.style.backgroundColor = "#FF7E00";
} else {
Menubase.style.backgroundColor = "#FF7E00";
}
}
myBtn.onclick = changeColor;
</script>