I am trying to set the visibility of a div element to visible or hidden depending on the previous state. i.e, I am trying to set the visibility to hidden when the element was previously visible and vice versa with an on click event.
html:
<div id="cartwin"></div>
css:
#cartwin {
position: fixed;
z-index: 9999;
right: 0%;
top: 7%;
background-color: black;
border: 1px solid white;
border-radius: 5px;
height: 40%;
width: 25%;
visibility: hidden;
}
js:
cart.onclick = function togglecart() {
const cart = document.getElementById('cartwin').style.visibility;
if (cart == 'visible') {
cart = 'hidden';
}
else if (cart == 'hidden') {
cart = 'visible';
}
}
This code has no effect at all, and I am inclined to believe it has to do with my if tests after a bit of looking around, but i could not find anything out.