Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing Nested Layers??

Status
Not open for further replies.

jchastai

Programmer
Oct 11, 2001
31
US
I have got a setup where I have a set of nested <div> tags and I need to figure out which <div> tag the user is hovering over when an onMouseOver event fires.

I have the following code right now ...

<div id=&quot;menuFrame&quot; class=&quot;menuFrame&quot; onMouseover=&quot;menuEvent(event)&quot;>
<div class=&quot;menuItem&quot;>Menu Item 1</div>
<div class=&quot;menuItem&quot;>Menu Item 2</div>
<div class=&quot;menuItem&quot;>Menu Item 3</div>
</div>

Checking event.srcElement.className in IE or e.target.className in NS6 correctly gives me 'menuItem' which is what I want.

I know NS 4 requires some additional code, but here is what I have and I cannot get it to work.

window.captureEvents( Event.MOUSEOVER );
window.onmouseover = function(e)
{ alert(e.target.className);
if (e.target.name.indexOf('menuItem') != -1)
{ menuEvent(e);
}
}

I threw in the alert because the function was never being called. It seems that the alert only fires for the &quot;outer shell&quot; <div> tag. It will not fire for any of the inner <div> tags.

Anybody got any ideas what I am doing wrong here?

Thanks for the help.
-- Jeff
 
aside from the fact that NS4 is bad, className is not accessible in it. Sorry. But for NS4 compatibility you will need to use a different system. Check hiermenus, or go to bratta.com there are a few options for you. I hope this helps. Sorry couldn't give you a better answer.

Gary Haran
 
Okay, if I cannot use className, is there a way I could give all of the 'menuItems' the same name or id and track them that way? Basically, I am just trying to figure out from which <div> the onMouseOver event was fired from.

(and yes I will agree, NS4 is a royal pain, but unfortunatly I have to support it)
 
I do not have a quick and easy way of doing this for you.

Maybe you should consider looking at existing code that does rollovers for Netscape 4 as well as all other browsers out there. as well as have good examples of menus that are full featured.

If you do want to access a div that is nested you will need to use recursion.


Has a good example. Take a look at gE() function. It shows an excellent recursion example on how to access a nested div no matter what level it is at. Almost what you want but still you will need to make some major changes to your code design in order to support NS4. Sorry about that. Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top