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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    2
    Thanked 0 Times in 0 Posts

    how can we know which element has been clicked

    is there any way to know which element(tag) has been clicked?

    regards
    san

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,524
    Thanks
    3
    Thanked 508 Times in 495 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[*/
    function Tst(){
     var zxcevt=window.event||arguments.callee.caller.arguments[0];
     var zxcobj=window.event?zxcevt.srcElement:zxcevt.target;
     alert(zxcobj.innerHTML);
    }
    /*]]>*/
    </script></head>
    
    <body>
    <div onclick="Tst();" >
    <div >Div 1</div>
    <div >Div 2</div>
    <div >Div 3</div>
    <div >Div 4</div>
    <div >Div 5</div>
    <div >Div 6</div>
    </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/

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    2
    Thanked 0 Times in 0 Posts

    problem in changing the object property at runtime

    hi friends,

    i am using this script to change the background color of <input> element at runtime.

    Code:
      <script language="javascript" type="text/javascript">
        function changebg(event)
    	  {
    	     event.srcElement.background='#EFFFFB';
    		 
    	  }
     </script>
    and this is being called by
    Code:
      <input onmouseover="changebg('event')" onclick="show_menu_pages('home')" style="position:absolute; left: 8%; top: 5% "  title="Home" type="image" name="" value="Home" src="/external/images/home.jpg">
    the background color seems not changed.

    any suggestion?

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,412
    Thanks
    11
    Thanked 595 Times in 575 Posts
    you were pretty close!

    try this cross browser compatible version:

    Code:
     function changebg(e)	  {
        e = e || window.event;
         var branch = e.srcElement ? "srcElement" : "target";
        e[branch].style.backgroundColor='#EFFFFB';
      }
    cheers!
    Last edited by rnd me; 10-21-2008 at 07:02 PM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


  •  

    Posting Permissions

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