Find the href of a link within a class - Javascript jQuery

Javascript examples for jQuery:Tag Traversing

Description

Find the href of a link within a class

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.0.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){/*from   w  ww .  ja va  2s .  c o m*/
$('a').click(function (e) {
        e.preventDefault(); // prevent default anchor behavior
        var goTo = this.getAttribute("href"); 
        console.log($(this).attr("href"));
    });
});

      </script> 
 </head> 
 <body> 
  <a href="http://java2s.com">BLOG</a>  
 </body>
</html>

Related Tutorials