473,379 Members | 1,235 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

onmouseout handler in list (quite strange)

Hi!

Javascript is doing something funny here. I expect that the onmouseout
handler "leave" should be called only when the mosuse has left the
entire list UL, but its triggered everytime, I move from one LI element
to the other. Why is this so?

Actually, I'm working on a collapsable menu (too long to post), and the
plan is to have make the onmouseout handler do the collapsing, and its
working excellently in IE, but not quite as well in NN, and FF.
Sometimes, the menu collapses when I move out, and at other times not.
Is there a Mozilla CSS fix for this? You know like -moz-user-select?
....

Thanks

- Olumide
////////////// HTML code ///////////////
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>

<script type="text/javascript">

function leave() {
alert("I left");
}

</script>

<STYLE>
li {
background-color: #FFFFFF;
font-weight: normal;
font-family: arial;
font-size: 12px;

text-align: center;
margin: 0;
padding: 0;
border: 1px solid black;
}

ul{
margin: 0;
padding: 0;
list-style: none;
width: 200px;
}

a {
display: block;
width: 200px;
text-decoration: none;
color: #000000;
}

</STYLE>

</head>

<body>

<ul onMouseOut="leave()">
<li><a href="#">Europe</a></li>
<li><a href="#">Africa</a></li>
<li><a href="#">America</a></li>
<li><a href="#">Asia</a></li>
</ul>

</body>
</html>

Jul 23 '05 #1
5 1583
<50***@web.de> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi!

Javascript is doing something funny here. I expect that the onmouseout
handler "leave" should be called only when the mosuse has left the
entire list UL, but its triggered everytime, I move from one LI element
to the other. Why is this so?

Actually, I'm working on a collapsable menu (too long to post), and the
plan is to have make the onmouseout handler do the collapsing, and its
working excellently in IE, but not quite as well in NN, and FF.
Sometimes, the menu collapses when I move out, and at other times not.
Is there a Mozilla CSS fix for this? You know like -moz-user-select?
...

Thanks

- Olumide


[snip]

I can't answer your question but:

a) under IE5.5 I get two alerts for each MouseOut;

b) removing "border: 1px solid black;" gives only one alert;

c) Firefix always gives only one alert per LI;

d) Netscape 6.2.2 doesn't give any alerts either way.
Jul 23 '05 #2
50***@web.de wrote:
Hi!

Javascript is doing something funny here. I expect that the onmouseout
handler "leave" should be called only when the mosuse has left the
entire list UL, but its triggered everytime, I move from one LI element
to the other. Why is this so?

Actually, I'm working on a collapsable menu (too long to post), and the
plan is to have make the onmouseout handler do the collapsing, and its
working excellently in IE, but not quite as well in NN, and FF.
Sometimes, the menu collapses when I move out, and at other times not.
Is there a Mozilla CSS fix for this? You know like -moz-user-select?
....

Thanks

[...]

There are some pure CSS menus here:

<URL:http://www.stylephreak.com/index.php/archives/2004/05/css-only-branching-menu/>

<URL:http://www.howtocreate.co.uk/tutorials/testMenu.html>

For an explanation of the differences between the IE and Geko event
models:

<URL:http://www.quirksmode.org/>

Follow the links: JavaScript -> Events

or start here (no frames):

<URL:http://www.quirksmode.org/js/introevents.html>

Be prepared for a lot of reading and play, but if you want to
understand events...

Lastly, using mouseover/out to trigger DHTML menus in Geko browsers
is notoriously flakey if you don't know what you are doing.

--
Fred
Jul 23 '05 #3
Odd. It fails for me too. But I got it to work by adding a dummy
onMouseOver:
<ul onMouseOver=() onMouseOut="leave()">
I am using IE.
....Jim Lee, Dallas, TX...

<50***@web.de> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi!

Javascript is doing something funny here. I expect that the onmouseout
handler "leave" should be called only when the mosuse has left the
entire list UL, but its triggered everytime, I move from one LI element
to the other. Why is this so?

Actually, I'm working on a collapsable menu (too long to post), and the
plan is to have make the onmouseout handler do the collapsing, and its
working excellently in IE, but not quite as well in NN, and FF.
Sometimes, the menu collapses when I move out, and at other times not.
Is there a Mozilla CSS fix for this? You know like -moz-user-select?
...

Thanks

- Olumide
////////////// HTML code ///////////////
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Untitled Document</title>

<script type="text/javascript">

function leave() {
alert("I left");
}

</script>

<STYLE>
li {
background-color: #FFFFFF;
font-weight: normal;
font-family: arial;
font-size: 12px;

text-align: center;
margin: 0;
padding: 0;
border: 1px solid black;
}

ul{
margin: 0;
padding: 0;
list-style: none;
width: 200px;
}

a {
display: block;
width: 200px;
text-decoration: none;
color: #000000;
}

</STYLE>

</head>

<body>

<ul onMouseOut="leave()">
<li><a href="#">Europe</a></li>
<li><a href="#">Africa</a></li>
<li><a href="#">America</a></li>
<li><a href="#">Asia</a></li>
</ul>

</body>
</html>

Jul 23 '05 #4
VK
Because the events are "bubbling" in the modern event model (IE as well
as all wonnabes). Other word, an event "bubble" pops up from the
deepest inderlaying element which is visible and enabled (<a> in your
case) and goes through the whole document structure to the very top
(which is window).
This very questionnable system is real easy for a privitive events
handling in a simple document (this is why it eventually won). From the
other side it makes a terrible mess in more or less complicated
situations.
An evident solution would be to do events "back tracing" to find out
which element really produced the event. Unfortunately it's nearly
impossible. W3 solution is done in unnecessary complicated and
contradicting way (as many other things they did). And IE "pseudo-W3"
solution is simply broken and I don't see any attempts to fix it over
the last two years.

You may use IE-exclisive solution this way:

function leave() {
if (window.event.toElement.tagName=='BODY') {
alert('Gocha!");
}
}
/* A question for million $: what if your list is not on the page
itself, but within another element like say <div>? You need to update
tagName== to the appropriate tag name. As you can see, IE proprietary
model sucks too. */

Jul 23 '05 #5
VK wrote:
[Event bubbling]
This very questionnable system is real easy for a privitive events
handling in a simple document (this is why it eventually won). From the
other side it makes a terrible mess in more or less complicated
situations.


Probably you are not willing to explain why you distribute such FUD here.
PointedEars
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tobias Hesselmann | last post by:
Hi folks, i have a problem using a PHP script as a custom handler in Apache. What i wanna do is this: Whenever a .html file is requested by a browser, i want Apache to call a CGI that outputs...
7
by: delerious | last post by:
I have a DIV that contains some anchors arranged vertically. On the DIV element I have an onmouseout event handler. If I move the mouse over one of the anchors, and then move it to another anchor...
1
by: Eric Adem | last post by:
Try out the following code: <html> <body> <table onMouseOut="alert('out');" width="50%" height="50%" bgcolor=yellow><tr><td> <table width="100%" height="100%"><tr valign=middle> <td...
7
by: Samir | last post by:
I would like to get a little window (101x73) to appear on onmouseover and go away onmouseout. the onclick works. <html> <head> <meta http-equiv="Content-Language" content="en-us"> <meta...
1
by: Greg A | last post by:
Hi: What can I add to this script to make it stop scrolling onmouseover, and resume onmouseout? Thanks. <script language="JavaScript"> function getObject( obj ) {
1
by: Gu | last post by:
hi to all! i have a strange behaviour when applying onmouseout to a layer. it is not trigged when the pointer goes out of the _layer_ but when it goes off the _text within_ the layer. any idea?...
6
by: Tom | last post by:
Hi, In the following code I have reproduced a problem in IE that is extremely annoying for my application. <html> <head> <script type="text/javascript">
2
by: Sugapablo | last post by:
I have a DIV that becomes visible when a link above it is moused over. The DIV has links in it like so: <div class="popup" onmouseout="hideLayer(this);"> <a class="popuplink"...
2
by: John Kotuby | last post by:
Hi guys, I am converting a rather complicated database driven Web application from classic ASP to ASP.NET 2.0 using VB 2005 as the programming language. The original ASP application works quite...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.