Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Closed Thread
onmouseout on div tag not working properly--bubbling problem?
Old 08-17-2009, 03:58 PM onmouseout on div tag not working properly--bubbling problem?
Average Talker

Posts: 29
Name: Luke
Trades: 0
I have this basic structure on my website:

Code:
 
<div ONMOUSEOUT goes here>
      <ul>
          <li><a></a></li>
          <li><a></a></li>
          <li><a></a></li>
      </ul>
      <div>
      ...
      </div>
</div>
I have onmouseover events for each li which is working fine. What is not working correctly is that the onmouseout event is triggered at times besides mousing out of the topmost level div. I saw someone refer to this as bubbling on a different site, but I dont know how to account for it. Can anyone help or refer me to somewhere that can?

Thanks!!!
__________________
Luke Robinson

Please login or register to view this content. Registration is FREE
lrobinson is offline
View Public Profile
 
 
Register now for full access!
Old 08-17-2009, 04:40 PM Re: onmouseout on div tag not working properly--bubbling problem?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Here's a good study guide that helps explain bubbling and event order: http://www.quirksmode.org/js/events_order.html
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
View Public Profile Visit wayfarer07's homepage!
 
Old 08-17-2009, 06:05 PM Re: onmouseout on div tag not working properly--bubbling problem?
Average Talker

Posts: 29
Name: Luke
Trades: 0
Thanks for the link...

I'm not really up on my javascript as well as I probably should be... In the cross browser compatible example:

Code:
 
function doSomething(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}
Looks like the same code twice for different broswers--can someone explain this a bit? I'm not sure where this is supposed to be called in my code--do I just add 2 elses to run my code if the if-conditions are not satisfied?

Really, Really appreciate it!
__________________
Luke Robinson

Please login or register to view this content. Registration is FREE
lrobinson is offline
View Public Profile
 
Old 08-17-2009, 06:56 PM Re: onmouseout on div tag not working properly--bubbling problem?
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
e.stopPropagation stops the event from bubbling to the parent element, and stops the default action from happening (link being followed, form being submitted, etc). This is the W3C standard way of handling things.

e.cancelBubble=true does the same thing, but for IE (stopPropogation isn't supported in this browser).
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
View Public Profile Visit wayfarer07's homepage!
 
Old 08-18-2009, 11:39 AM Re: onmouseout on div tag not working properly--bubbling problem?
Average Talker

Posts: 29
Name: Luke
Trades: 0
Wayfarer,

Thanks for explaining the W3C vs IE requirements, but I still am not having any success. My code has changed a bit while working on it, here is the latest (very similar). Thanks so much in advance!

html:

Code:
 
<div onmouseout="addStyle('feat_main');" >
      <ul>
          <li><a></a></li>
          <li><a></a></li>
          <li><a></a></li>
      </ul>
      <div>
      ...
      </div>
</div>
Functions:

Code:
 
function addStyle(e, x)
{
 if (!e) var e = window.event;
 e.cancelBubble = true;
 if (e.stopPropagation) e.stopPropagation();

 removeAllStyle();
 document.getElementById(x).style.display="block";
}
 
function removeAllStyle()
 {
     removeStyle('feat_main');
     removeStyle('feat_hurricane');
     removeStyle('feat_fabrication');
     removeStyle('feat_capsnap');
     removeStyle('feat_medical');
     removeStyle('feat_media');
 }
__________________
Luke Robinson

Please login or register to view this content. Registration is FREE
lrobinson is offline
View Public Profile
 
Old 08-18-2009, 06:50 PM Re: onmouseout on div tag not working properly--bubbling problem?
Average Talker

Posts: 29
Name: Luke
Trades: 0
I cannot for the life of me get this code to work properly in any browser! (Though I'm closer thanks to help on this forum) All I have been trying to achieve the last 2 days is to get the addStyleDiv function to only call the addStyle function when it sees that it is mousing out of the div with id='rollover'

That is, not call addStyle on the elements within the div, only when it is completely outside of the rollover div. Right now, every element within the rollover div triggers the onmouseout event except mousing out of the actual rollover div. (the exact opposite of what I want) I would like this to work on all mainstream browsers, so please let me know if my code will only work with some (and how to fix it).

Latest html:
Code:
 
<div id="rollover" onmouseout="addStyleDiv(event,'feat_main');">
<ul id="featured">  
<li class="medical" onmouseover="addStyle('feat_medical');"><a href="equipment/medical">Medical</a></li>
<li class="fabrication" onmouseover="addStyle('feat_fabrication');"><a href="services/metal_fabrication">Fabrication</a></li>
<li class="capsnap" onmouseover="addStyle('feat_capsnap');"><a href="equipment/capsnap">CapSnap&trade;</a></li>
<li class="hurricane" onmouseover="addStyle('feat_hurricane');"><a  href="equipment/parts_washing/hurricane">Hurricane</a></li>
<li class="media" onmouseover="addStyle('feat_media');"><a href="video">Media</a></li>
</ul>
<div id="flyout" >
    <ul id="feat_main">
        <h1>Midbrook</h1>
        standard page no rollover
    </ul>
    <ul id = feat_medical>
        <h1>Medical</h1> 
    </ul>
    <ul id = feat_fabrication>
        <h1>Fabrication</h1>
    </ul> 
    <ul id = feat_capsnap>
        <h1>CapSnap</h1>
    </ul>
    <ul id="feat_hurricane">
        <h1>Hurricane</h1>
    </ul>
    <ul id = feat_media>
        <h1>Media</h1>
    </ul>   
</div>
</div>
latest JS functions:
Code:
 
 
function addStyleDiv(e, x)
{
   if (!e) var e = window.event;
   var tg=(window.event) ? e.srcelement : e.target;
 
 if (tg.id != 'rollover') 
 {
     alert('leaving '+tg.tagName + ' '+tg.id);
     return;
 }
   /*These next two lines are NEVER reached no matter what*/
   alert('It must have finally seen rollover');
   addStyle('feat_main');
}
 
function addStyle(x){
 removeAllStyle();
 document.getElementById(x).style.display="block";
}
function removeAllStyle()
 {
     removeStyle('feat_main');
     removeStyle('feat_hurricane');
     removeStyle('feat_fabrication');
     removeStyle('feat_capsnap');
     removeStyle('feat_medical');
     removeStyle('feat_media');
 }
Thanks so much in advance. I'm dying to have this working.
__________________
Luke Robinson

Please login or register to view this content. Registration is FREE

Last edited by lrobinson; 08-18-2009 at 07:36 PM.. Reason: the tab key put the submit button in focus. oops :-)
lrobinson is offline
View Public Profile
 
Closed Thread     « Reply to onmouseout on div tag not working properly--bubbling problem?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.11151 seconds with 12 queries