hide a div with javascript with onmouseout

Discussion in 'JavaScript' started by panzhuli, Jul 19, 2007.

  1. #1
    hey all. i don't know js well at all. i'm trying to hide a div when the mouse rolls off it (dd menu). It is only sometimes hiding it. here's what i have:

    <div id="dropdown_menu" onmouseout="doSomething(event);">
    <ul>
    <li>anchor tag with rollover image</li>
    <li>anchor tag with rollover image</li>
    </ul>
    </div>

    and the script (I found on the web)

    function doSomething(e) {
    if (!e) var e = window.event;
    var tg = (window.event) ? e.srcElement : e.target;
    if (tg.nodeName != 'DIV') return;
    var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
    while (reltg != tg && reltg.nodeName != 'BODY')
    reltg= reltg.parentNode
    if (reltg== tg) return;
    // Mouseout took place when mouse actually left layer
    // Handle event
    hidediv("dropdown_menu");//another fx that works fine
    }


    thanks in advance.
     
    panzhuli, Jul 19, 2007 IP
  2. nfd2005

    nfd2005 Well-Known Member

    Messages:
    295
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #2
    function hidediv(divid) {
    document.getElementById(divid).style.display='none';
    }


    Try that.
     
    nfd2005, Jul 19, 2007 IP
  3. panzhuli

    panzhuli Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it will hide the div, but it isn't registering the onmouseout properly. ideas?
     
    panzhuli, Jul 20, 2007 IP
  4. nfd2005

    nfd2005 Well-Known Member

    Messages:
    295
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    130
    #4
    I guess I need to know exactly what you want to accomplish.
     
    nfd2005, Jul 20, 2007 IP
  5. aRo`

    aRo` Peon

    Messages:
    141
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    if you need to change a lot of js object attributes i really suggest to use a javascript framework such as jquery, prototype, mootools...

    I've been using jQuery for a while now and it really rocks :)
     
    aRo`, Jul 22, 2007 IP