Get Id of link and output with console.log - Javascript Language Basics

Javascript examples for Language Basics:console

Description

Get Id of link and output with console.log

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <style>



      </style> 
   </head> 
   <body> 
      <a id="1" onclick="reply_click(this.id)" href="#">Link 1</a> 
      <a id="2" onclick="reply_click(this.id)" href="#">Link 2</a> 
      <a id="3" onclick="reply_click(this.id)" href="#">Link 3</a> 
      <script>
        function reply_click(clicked_id) {
            console.log("You have clicked Link " + clicked_id);
        }//from   w  w  w .j av  a2  s  .  co m
    
      </script>  
   </body>
</html>

Related Tutorials