This is very useful for javascript devopers that how to get anchor tag href value in jquery, most of the time we use onclick kind of event’s function passing the value through it but now don’t take any kind of risk here, just use only <a> tag href value and get the value if you clicked on it.

Complete example is available in the below.

<html>
<head>
<title>Jquery find the anchor tag href value example</title>
<script type=”text/javascript” src=”http://code.jquery.com/jquery-latest.js”></script>
<script type=”text/javascript”>
$(document).ready(function() {
$(“a”).click(function(event) {
alert(“You have clicked on <a> link”);
var href = $(‘a’).attr(‘href’);
alert(href);
event.preventDefault();
});
});
</script>
</head>
<body>
<a href=”http://www.webtutorialspoint.com/”>www.webtutorialspoint.com</a>
</body>
</html>

Please share it in SM.

 

491 Total Views 4 Views Today

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>