Sometimes we need to set and get value of href attribute of <a> tag from jQuery. We can do this very easily by using element.attr() function in jQuery.
Example: for example you declare an <a> as below:
<a id="element_url" href="#"></a>
To get the href attribute of <a> tag, use the below code:
var url = $('#element_url').attr('href');
To set the href attribute of <a> tag, use the below code:
$('#element_url').attr('href','http://www.google.com');
Hope this will help you :)
0 Comment(s)