Javascript examples for jQuery:Tag Traversing
Find the href of a link within a class
<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>