I'm currently working on a side menu that drops down when hovering over Section One within the <a>
tag. I need some guidance on how to make the JavaScript code continuously check the state of the list after a set amount of time in order to automatically close the menu. Can anyone offer some assistance?
HTML
<div class = "sidebarwrap">
<ul>
<li>
<a href="#" onmouseover="toggle(this); return true;" onmouseout="timer()">Section One</a>
<ul>
<li><a href="#" >link page</a></li>
<li><a href="#" >link page</a></li>
<li><a href="#" >link page</a></li>
<li><a href="#" >link page</a></li>
</ul>
</li>
</ul>
</div>
CSS
.sidebarwrap{
width:auto;
height:auto;
}
.sidebarwrap ul{
float:left;
display:block;
background:white;
padding:10px;
margin-right:30px;
margin-left:10px;
list-style-type:none;
border:1px dotted #0099CC;
border-radius:100px/10px;
}
.sidebarwrap ul ul{
list-style-type:none;
display:none;
border:0px dotted #0099CC;
border-radius:20px/60px;
}
.sidebarwrap li li{
list-style-type:circle;
border:0px dotted #0099CC;
border-radius:20px/60px;
padding:5px;
}
JavaScript
var cssNode = document.createElement('link');
cssNode.setAttribute('rel','stylesheet');
cssNode.setAttribute('type','text/css');
cssNode.setAttribute('href', 'javascript-overrides.css');
document.getElementsByTagName('head')[0].appendChild(cssNode);
function toggle(toggler) {
if(document.getElementById){
targetElement = toggler.nextSibling;
if(targetElement.className == undefined){
targetElement = toggler.nextSibling.nextSibling;
}
if (targetElement.style.display == "block") {
targetElement.style.display = "none";
} else {
targetElement.style.display = "block";
timer();
}
}
}
function timer(){
var Time = setTimeout(function(){toggle(toggler)},1000);
}