When the user clicks on a div, it expands or closes. I also want to adjust the top position of another fixed div based on the state of the original div.
For instance:
If the original div is expanded, I want the second div to have top:10px
If the original div is closed, I want the second div to have top:0
Below is the current toggle function for expanding or closing the div:
<a href="#" class="toggle" onclick="dropDownMSG(); this.parentNode.classList.toggle('open');return false;">
<img src="/Static/images/header-logo-top.png" alt="Informa logo"/>
</a>
Then below I have:
function dropDownMSG() {
document.getElementById("mySidenav").style.top = "10";
}
However, this only sets top:10px
on click. So when toggled again to close the div, the top
does not reset to 0
.
I need a way to specify:
if toggle is open then
document.getElementById("mySidenav").style.top = "10";
Else
document.getElementById("mySidenav").style.top = "0";