I am trying to create a function on my hamburger icon to show an element in smaller screens which is manipulated as display:none directly in my css. I am able to make it appear on the screens that are below 800px when toggled but it dissappears quickly in a matter of just few milliseconds. i have been figuring out what should be done but i couldnt find answers.
HTML
<body>
<nav>
<a class="toggle" href="" onclick = "func1()"><i class="fas fa-bars" >
</i></a>
<ul id="defaultnav" class="topnav">
<li class="current"><a class = "navlinks" href = "">Home</a></li>
<li><a class = "navlinks" href = "Services.html">Services</a></li>
<li><a class = "navlinks" href = "About.html">About</a></li>
<li><a class = "navlinks pointer"
onclick="document.getElementById('id01').style.display='block'"
style="width:auto;">Login</a></li>
<li><a class = "navlinks" href = "Signup.html">Sign Up</a></li>
</ul>
</nav>
<script src="./script/test.js"></script>
</body>
CSS
.toggle {
width:100%;
margin:0;
padding:0 15px 0 0 ;
font-size:20px;
display:none;
color:#ffd34f;
}
.toggle:hover{color:white;}
@media screen and (max-width:800px){
#defaultnav{display:none;}
.toggle{display:block;}
}
@media screen and (max-width:800px){
#defaultnav.responsive {
display:block;
position: fixed;
padding: 20px;
border: 2px solid #FFB600;
background:#1a1a1a;
right: 15px;
width: 50%;
border-radius: 20px 0 15px 10px;
z-index:99999;
}
#defaultnav.responsive li {
text-align: center;
width: 100%;
padding: 10px 0;
margin: 0;
}
}
JAVASCRIPT
function func1() {
var x = document.getElementById("defaultnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
navtag and afterbodythenavhas to be insidebody