/    Sign up×
Community /Pin to ProfileBookmark

Help! onmouseover menu problems…

Hello everyone i am quite new to javascript and thought i would try making a onmouseover menu which hides and shows the visibility on mouseover…yet i am having problems

If anyone could show me where i have gone wrong it would be a great help, here was my theory..

1/ find the ul’s on the page
2/ loop through the ul’s…set the ones with id’s to visible on mouseover
3/ Set the mouseout on the now visible menu

the problem is when i mouseout off the UL onto the LI the menu collapses

help?!

[CODE]
<Style type=”text/css”>
div#subNav_home {border:1px solid red; visibility:hidden;}
div#subNav_home li {z-index:0; background-color:green; }
</Style>
</head>

<body>
<ul class=”navigation”>
<li><a href=”#” id=”navigation_home”>Menu</a>
<ul id=”subNav_home”>
<li>one</li>
<li>two</li>
<li><a href=”#”>three</a></li>
</ul>
</li>
</ul>

<script type=”text/javascript”>

var homeMenu = document.getElementById(“navigation_home”);
var ul = document.getElementsByTagName(“ul”);

function popup() {
for(i=0; i < ul.length; i++) {
if(ul[i].getAttribute(“id”) != null) {
ul[i].style.visibility=”visible”;
ul[i].onmouseout = function() {
this.style.visibility=”hidden”;

}
}
}
}

homeMenu.onmouseover = function() {
popup();
}

</script>
[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Angry_Black_ManAug 01.2007 — the problem is when i mouseout off the UL onto the LI the menu collapses[/quote]

[CODE]
ul[i].onmouseout = function() {
this.style.visibility="hidden";
}
[/code]


once you mouse onto an LI, it says, "well, im not on a UL anymore!" because it truly isnt. its on an LI (or body or whatever else)

basically, there isn't a nested effect like you think there is... you'd expect the LI to still be apart of the parent UL. while it is for DOM and other purposes, your code is working exactly as intended. an LI is not a UL despite nesting, thus your issue.

you'd have to go hardcore, id imagine to get this to work.. for instance, if the li you are on is a child of the UL you moused onto, dont hide the parent UL. but if you leave the LI, find its parent UL and then hide it.

only problem with that is how can you ever get the parent to show up again?
Copy linkTweet thisAlerts:
@adamdudeauthorAug 01.2007 — Hey yeah i kind of thought that. although i dont know an alternate solution, any ideas or suggestions anyone?

thankyou
×

Success!

Help @adamdude spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...