I'm new to JavaScript. I wanna change the color of menu button when I click on it and change the color back when I click it second time. I wrote a simple code in JS, but it does nothing.
document.getElementById("menuBtn div").onclick = changeColor;
function changeColor() {
if (changeColor.style.backgroundColor === "#EF6A6A") {
changeColor.style.backgroundColor = "#fff"
} else {
changeColor.style.backgroundColor = '#EF6A6A'
}
}
changeColor()
#menuBtn {
position: fixed;
display: block;
cursor: pointer;
right: 65px;
top: 35px;
z-index: 2;
cursor: pointer;
}
#menuBtn div {
width: 38px;
height: 5px;
background-color: #EF6A6A;
margin: 8px;
border-radius: 2100px;
transition: all 0.3s ease;
}
<div id="menuBtn">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>