Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to set multiple attribute values using jQuery?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.97k
    Comment on it

    Hello friends,

    Today we learn to change the multiple attribute value using jQuery. To set multiple attribute value we will use a jQuery attr() method. This method is used for changing the attribute values. We can change multiple attributes with the help of attr() method at the same time.

    Let's understand this with an example. Suppose we have a link and a button. We need to change the href and title of link on click of the button. To perform this task we need to execute the following code:

    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("button").click(function(){
            $("#changelink").attr({
                "href" : "http://newsite.com",
                "title" : "This is the new title"
            });
        });
    });
    </script>
    </head>
    <body>
    
    <a href="http://oldsite.com" title="old title" id="changelink">Link</a>
    
    <button>Click here to change the attribute</button>
    
    </body>
    </html>

     

 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: