I am trying to make an element #mask123visible or hidden when clicked. By default, the element is hidden, but when clicked, it becomes visible. The js below works on the first click, and the element becomes visible. Now I would like to click on the same button #menu-btn-toggle, and the element will switch to invisible mode, and I can not make it work. I am using inline css here. This is a simple case, but my limited knowledge of js does not help me.
<div id="menu-btn">
<a href="#" title="Menu" id="menu-btn-toggle" class="menu-icon-link" onclick="showMask();">
</div>
html code
<div class="side-nav--mask">
<div class="js-side-nav-mask liquid-container">
<div id="mask123" class="liquid-child" style="visibility: hidden; top: 0px; left: 0px; opacity: 1;"></div>
</div>
</div>
Here is my JS:
<script type="text/javascript">
function showMask() {
var node = document.getElementById('mask123')
node.style.visibility = 'visible';
}
</script>
When I try to fulfill the condition (below), this does not work:
<script type="text/javascript">
function showMask() {
var node = document.getElementById('mask123')
node.style.visibility = 'visible';
if node.is(":visible") {
node.style.visibility = 'hidden';
}
}
</script>
source
share