In this article we will learn how to get href value property for anchor tag in jquery using attr() property. Below example when the user clicks the about link button alert will show the href property value.
Example:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>get href propertyvalue in anchor tag using jquery</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#mnuAbout").click(function (event) {
var href = $(this).attr('href');
alert(href);
event.preventDefault();
});
});
</script>
<style type="text/css">
a {
color: #00BCD4;
padding: 10px;
}
a:hover {
color: #FF9800;
}
</style>
</head>
<body style="font-family: Arial; border: 1px solid #DED8D8; width: 500px;">
<h2 style="color: #E91E63;">get href property value in anchortag using jquery</h2>
<div style="text-align: center">
<p><a class="menuButton" id="mnuHome" href="http://www.infinetsoft.com">Home</a></p>
<p><a class="menuButton" id="mnuAbout" href="http://www.infinetsoft.com/about">About</a></p>
<p><a class="menuButton" id="mnuContact" href="http://www.infinetsoft.com/contact">Contact Us</a></p>
<p style="color: #071D98;">
click on about link to get href propertyvalue
</p>
</div>
</body>
</html>
Output:
Post your comments / questions
Recent Article
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
- expected str, bytes or os.PathLike object, not JpegImageFile - Python
Related Article