Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jquery attr() function

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 5
    • 0
    • 146
    Comment on it

     

    The jquery attr() method help users to return the values of first selected elements as well as we can also set the values of attribute(i.e one or more attribute values.)

    Syntax :

     

    //Return the value of an attribute:

          $(selector).attr(attribute)

    //Set the attribute and value:

         $(selector).attr(attribute,value) (attribute: it's the name of attribute and value: corresponding value of attribute)

     

    Example :

    <!Doctype html>
    <html>
      <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
      </head>
      <body>
        <img src="xyz.png" width="240px" height="250px"><br>
        <button>Image height will increase on clicking</button>
      </body>
    </html>
    

    In above code i have included the jquery.min file in which some tag is predefined. Using this example i want to tell you that we can change the values of image(i.e width and height ) .

    Jquery Code :

    <script>
    $(document).ready(function(){
        $("button").click(function(){
            $("img").attr("height", "500");
        });
    });
    </script>

    Output :

    Befor clicking on the button :

    After clicking on the button :

     

     

    jquery attr() function

 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: