Saturday, November 21, 2009

Javascript - Passing events

<script language="javascript" type="text/javascript">
  function hide(elementId, event) {
     document.getElementById(elementId).style.visibility = 'hidden';
     alert(event.type); //type of event because of which this function was called
     /*firefox: used to get the element that handled this method... the exact caller.
         <div id="outer" onmouseout="hide('outer', arguments[0])">
            <div id="inner"></div>
         </div>
*/
     //firefox: In this case "outer" will be returned   
    
alert(arguments.callee.caller);
        //firefox: the exact element that gave rise to this event. "inner" from above example.
        alert(event.target.id);
   }
</script>
.
.
.
<body>
     <span onmouseout="hide('elementId', arguments[0])">Something</span>
</body>


More event object properties are at this website.




No comments: