473,811 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

event.stopPropa gation() does not work

I have a DIV that contains some links. I have an onmouseout event handler on
the DIV, and I want it triggered only when the mouse leaves the DIV. Since
there are Anchors in the DIV, onmouseout events will be generated when the
mouse moves from one link to another, and those events will bubble up to the
DIV. According to all the documentation that I have read, I should be able to
prevent that from happening by having an onmouseout event handler for each of
the anchors, and calling event.stopPropa gation in the event handler. But it
is not working in Mozilla and Opera, the onmouseout still bubbles up from the
anchor to the DIV. I have it working in IE, but that is because IE does not
support stopPropagation (), and instead uses window.event.ca ncelBubble=true ,
which Mozilla and Opera do not support.

Does anyone have any clue why stopPropagation () isn't working in Mozilla and
Opera?

You can see the problem in action here:
http://home.comcast.net/~delerious1/index4.html

Here is my HTML code:

<BODY onload="init()" >
<DIV id="submenu" onmouseout="ale rt('Mouse has just left the DIV')">
<A href="fakepage. html">LINK 1</A>
<A href="fakepage. html">LINK 2</A>
<A href="fakepage. html">LINK 3</A>
<A href="fakepage. html">LINK 4</A>
<A href="fakepage. html">LINK 5</A>
</DIV>
</BODY>
Here is my Javascript code:

function init() {
var submenu = null;
if (document.getEl ementById)
submenu = document.getEle mentById('subme nu');

for (var i=0; i<submenu.child Nodes.length; i++) {
if (submenu.childN odes[i].addEventListen er) {
// this code is for Mozilla and Opera
submenu.childNo des[i].addEventListen er('mouseout',
disableEventPro pagation, false);
}
else if (submenu.childN odes[i].attachEvent) {
// this code is for IE
submenu.childNo des[i].attachEvent('o nmouseout',
disableEventPro pagation);
}
}
}

function disableEventPro pagation(event) {
if (event.stopProp agation) {
// this code is for Mozilla and Opera
event.stopPropa gation();
}
else if (window.event) {
// this code is for IE
window.event.ca ncelBubble = true;
}
}
Here is the stylesheet I am using:

DIV {
background-color: red;
left: 10px;
top: 10px;
position: absolute;
}

A {
background-color: blue;
color: white;
display: block;
margin: 0 0 5px 0;
text-decoration: none;
}

A:hover {
background-color: cyan;
}

Jul 20 '05 #1
3 16949


de*******@no.sp am.com wrote:
I have a DIV that contains some links. I have an onmouseout event handler on
the DIV, and I want it triggered only when the mouse leaves the DIV. Since
there are Anchors in the DIV, onmouseout events will be generated when the
mouse moves from one link to another, and those events will bubble up to the
DIV. According to all the documentation that I have read, I should be able to
prevent that from happening by having an onmouseout event handler for each of
the anchors, and calling event.stopPropa gation in the event handler. But it
is not working in Mozilla and Opera, the onmouseout still bubbles up from the
anchor to the DIV. I have it working in IE, but that is because IE does not
support stopPropagation (), and instead uses window.event.ca ncelBubble=true ,
which Mozilla and Opera do not support.


See
http://www.faqts.com/knowledge_base/...d/1606/fid/145
for a solution, there is no need to set up event handlers for all those
descendant elements and to try to stop events from propagating, simply
use event.relatedTa rget to distinguish a mouse leaving the element from
the mouse leaving a child element.


--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2


de*******@no.sp am.com wrote:
I have a DIV that contains some links. I have an onmouseout event handler on
the DIV, and I want it triggered only when the mouse leaves the DIV. Since
there are Anchors in the DIV, onmouseout events will be generated when the
mouse moves from one link to another, and those events will bubble up to the
DIV. According to all the documentation that I have read, I should be able to
prevent that from happening by having an onmouseout event handler for each of
the anchors, and calling event.stopPropa gation in the event handler. But it
is not working in Mozilla and Opera, the onmouseout still bubbles up from the
anchor to the DIV. I have it working in IE, but that is because IE does not
support stopPropagation (), and instead uses window.event.ca ncelBubble=true ,
which Mozilla and Opera do not support.

Does anyone have any clue why stopPropagation () isn't working in Mozilla and
Opera?

You can see the problem in action here:
http://home.comcast.net/~delerious1/index4.html


Well, write some code to inspect what is happening, for instance

javascript: var el = document.getEle mentById('subme nu'); el.onmouseout =
function (evt) { alert(evt.type + ' for target ' + evt.target + ' with
relatedTarget ' + evt.relatedTarg et); }; void 0

then you will see that mouseout events are fired on the div when the
mouse moves over a child element. The mouse can always only be over one
node so when the mouse has entered the div but then enters a child
element or node of the div then mouseout is fired on the div.
For an approach to handle the mouse leaving the div see my earlier posting.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #3
On Thu, 11 Dec 2003 12:03:19 +0100, Martin Honnen <ma*******@yaho o.de> wrote:
Well, write some code to inspect what is happening, for instance

javascript: var el = document.getEle mentById('subme nu'); el.onmouseout =
function (evt) { alert(evt.type + ' for target ' + evt.target + ' with
relatedTarge t ' + evt.relatedTarg et); }; void 0

then you will see that mouseout events are fired on the div when the
mouse moves over a child element. The mouse can always only be over one
node so when the mouse has entered the div but then enters a child
element or node of the div then mouseout is fired on the div.
For an approach to handle the mouse leaving the div see my earlier posting.


Thanks for the replies. This will surely help me out.

Jul 20 '05 #4

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

Similar topics

2
11281
by: Barton | last post by:
Hello, I've got a table row with an onClick event that loads page1. Now I do not want to apply this event to one cell of that row because that cell contains already a link to another page. How do I disable the onClick event on that one cell? Code: <table> <tr onClick="window.location=page1.html'> <td></td>
1
2624
by: SomeGei | last post by:
Hey guys.... i have a really big table... and the <tr> tags have onclick/onmouseover events that highlight a row when you drag your mouse over it, and open a popup window when you click anywhere in the row... if i however have some text in the row that has an href link attached to it, when i click on the link it will go to the href url AND open the popup window...
4
8991
by: phil_gg04 | last post by:
Dear Javascript Experts, I'm currently implementing Anyterm, a terminal emulator on a web page. It consists of an Apache module, some XmlHTTP and a bit of Javascript. The idea is to give you shell access to your server from (almost) anywhere; other solutions to the problem tend to require access to ports other than 80 and Java. The very primitive first attempt is at http://chezphil.org/anyterm/. A more functional version will be...
10
13932
by: David | last post by:
Is there something that I can use to prevent the a user from dragging something, an image for instance. In IE I can use the ondrag = "return false;", is there a way to achieve the same way with the other browsers? Thanks, David
17
10223
by: dan_williams | last post by:
I have the following test web page:- <html> <head><title>Test</title> <script language="Javascript"> <!-- function fnTR() { alert("TR"); }
3
1365
by: gert | last post by:
<table onclick="do_something()"> <tr> <td id=1 onclick="do_something_else()"></td> </tr> <tr> <td id=2></td> </tr> </table> how can i make a do_something event that only happens when the
6
2670
by: blaine | last post by:
Hello, I'm currently overriding function keys (F1 to F4) to perform other actions. In order to do this the default popup windows of Help (F1), Seach(F3) etc must be turned off. In FF it's easy enought to do using the preventDefault and stopPropagation event functions. IE's equivalent is supposed to be cancelBubble and returnValue, however I can not seem to get them to stop no matter what I try.
3
11759
by: Chamnap | last post by:
Hello everybody, I have one problem. I want to do something after the user finished scrolling. The scroll event fires whenever the user is scrolling. I don't want this actually. Does anyone has any idea or trick of how to achieve this? Appreciate your ideas..... Thanks Chamnap
8
3225
Jezternz
by: Jezternz | last post by:
I came across a very interesting problem recently. Basicly I am building an editor and I want to take advantage of hot keys. I got it working perfectly in Internet Explorer, But I hit problems when I tried in Firefox, stranger still I found Chrome worked fine. The problem is the use of hotkeys that are already used in firefox. In my example I have used Ctrl-S (Save page in both FF and Ch). Now I would think evt.preventDefault(); would be the...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10392
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10403
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5555
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3868
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.