Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set and get href attribute in jQuery?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 753
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: