I'm attempting to create a navigation bar with submenus, but I keep encountering errors such as "dropMenu is not defined" and "Uncaught TypeError: Cannot read property 'style' of null" when hovering over the Paris links. Any thoughts on what might be causing this issue? Here is my code:
<html>
<link type="text/css" rel="stylesheet" href="vacation.css"/>
<head>
<title>Paris</title>
</head>
<body>
<div id="menus">
<div id ="parismenu">
<a href="#" onmouseover="dropMenu('dropmenu1')">Paris</a>
<div id="dropmenu1" class="dropmenus">
<a href="#">apple</a>
</div>
</div>
<div id ="disneymenu">
<a href="#" onmouseover="dropMenu('dropmenu2')">Paris</a>
<div id="dropmenu2" class="dropmenus">
<a href="#">apple</a>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>
<script type="text/javascript" src="vacation.js"></script>
</html>
CSS
div#menus{
margin-left:16px;
}
div#menus> div{
float:left;
margin:0px 20px;
}
div.dropmenus{
display:none;
position:absolute;
top:100px;
width:120px;
background:teal;
z-index:2;
padding:4px;
border: blue 3px solid;
border-top:none;
border-radius:5px 5px 5px 5px;
}
div.dropmenus>a{
display:block;
margin:4px;
padding:7px;
font-size:14px;
text-decoration:none;
background:blue;
border-radius:3px;
color:red;
}
div#dropmenu1{
left:24px;
}
div#dropmenu2{
left:116px;
}
Javascript
var fade=function(){
return{
init:function(id,flag,target){
this.elem=document.ElementById(id);
clearInterval(this.elem.si);
this.target=target ? target : flag ? 100 : 0;
this.flag = flag||1;
this.alpha = this.elem.stle.opacity ? parseFloat(this.elem.style.opacity) * 100 : 0;
this.elem.si=setIntterval(function(){fade.fadep()},20);
},
fadep:function(){
if(this.alpha==this.target){
clearInterval(this.elem.si);
}
else{
var value=Math.round(this.alpha + ((this.target - this.alpha) * .05)) +(-1 * this.flag);
this.elem.style.opacity=value/100;
this.elem.style.filter='alpha(opacity=' + value + ')';
this.alpha=value
}}}}();
var menu= ["dropmenu1","dropmenu2","dropmenu3"];
function dropMenu(x){
for(var m in menu){
if(menu[m] != x){
document.getElementById(menu[m]).style.display="none";
}}
if(document.getElementById(x).style.diplay=="block"){
fade.init(x,1);
}
else{
fade.init(x,0)}}