Use this to reference current element during event handling - Javascript DOM

Javascript examples for DOM:Event

Description

Use this to reference current element during event handling

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*from   w  w  w .j  a va  2s  .c  o  m*/
document.getElementById('red').onclick = function(){
    this.style.color = "red";
}
    }

      </script> 
   </head> 
   <body> 
      <ul> 
         <li>
            <a id="red" href="#">List Item with Function</a>
         </li> 
         <li>
            <a href="#">List Item without Function</a>
         </li> 
      </ul>  
   </body>
</html>

Related Tutorials