Get Div Id where mouse was clicked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arggg
    New Member
    • Mar 2008
    • 91

    Get Div Id where mouse was clicked

    I'm trying to get the Div ID that the mouse was clicked in so that if it was not clicked in id ('divContext') then it will hide ('divContext'). What I have right now works perfect in FF but not in IE. The div will not go away even when a link is clicked.

    [code=javascript]
    //see if the focus has been taken off of the div and if so hide it.
    function on_down(e)
    {
    //alert('test');
    if (e == null) { e = window.event; }
    var evt = e.target || e.srcElement;
    //alert(evt.id);
    if (evt.id != 'divContext' && evt.id != 'aView' && evt.id != 'aComplete')
    {
    if (document.getEl ementById('divC ontext').style. display != 'none')
    {
    document.getEle mentById('divCo ntext').style.d isplay = 'none';
    }
    }
    }
    // See if a link in the div was clicked.
    function on_up(e)
    {
    if (e == null) { e = window.event; }
    var evt = e.target;
    //alert(evt.id);
    if (evt.id == 'aView' || evt.id == 'aComplete')
    {
    if (document.getEl ementById('divC ontext').style. display != 'none')
    {
    document.getEle mentById('divCo ntext').style.d isplay = 'none';
    }
    }
    }

    onload=function ()
    {
    onmousedown = on_down;
    onblur = on_down;
    onmouseup = on_up;
    }
    [/code]

    Anyone know why this will not work in IE?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    For the on_up function, you forgot the srcElement part (which you have in the on_down) function.

    Comment

    Working...