Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to determine if onmousedown occur in a specific object

    Can you help me with this:

    i capture onmousedown for the whole document
    document.onmousedown=hideDIV;

    onmousedown outside the DIV should hide the DIV
    onmousedown in the <DIV id='j_sel'> should do nothing
    how can i know that the onmousedown occured in that DIV ?

    function hideDIV() {
    var o_j = getObj('j_sel');

    // ??????
    // ??????

    o_j.style.display = 'none';
    divSet = false;
    }

    Cannot figure out this myself, because i am not a real javascript programmer.
    Thanks.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,467
    Thanks
    3
    Thanked 495 Times in 482 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    
    <script language="JavaScript" type="text/javascript">
    /*<![CDATA[*/
    
    document.onmousedown=function(event){ MseDown(event) };
    
    function MseDown(){
     var zxcevt=window.event||arguments.callee.caller.arguments[0];
     var zxcobj=arguments[0]?arguments[0].target:event.srcElement;
     if (zxcobj.id&&zxcobj.id=='j_sel') document.getElementById('j_sel').style.visibility='hidden';
    }
    /*]]>*/
    </script>
    </head>
    
    <body>
    <div id='j_sel' style="width:50px;height:50px;background-Color:red;" ></div>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •