The purpose of this function is to make the second button appear after one second of the click on the first button. And make it disappear after a new click on the same button. But what happens is that after the second click the second button disappears and returns a second later, which is not required in the function. I checked it completely and it looks okay. But it is not working as it should.
function botao_home() {
document.getElementById('mobile_index').style.display = 'block';
}
var onof1 = '0';
function showhide() {
if (onof1 == '0') {
setInterval(botao_home, 1000);
onof1 = '1';
} else {
document.getElementById('mobile_index').style.display = 'none';
onof1 = '0';
/*Note that second click should only set the display property of id "mobile_index" to "none".
But it is making the second button return, and this was not requested.*/
}
}
#mobile_index {
display: none
}
a {
display: block;
margin: 30px;
padding: 40px;
background: seagreen;
color: palegreen;
font-family: verdana, helvetica, arial, tahoma;
}
<div>
<a style="cursor:pointer" onclick="showhide()">Show/Hide</a>
<a id="mobile_index">Página Inicial</a>
</div>