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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 175
    Comment on it

    The jQuery attr() method is used to set or return attributes and values of the selected elements.

    Syntax :

    $(selector).attr(attribute)  
    

    Example:

    <!DOCTYPE html>  
    <html>  
    <head>  
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
    <script>  
    $(document).ready(function(){  
        $("button").click(function(){  
            $("img").attr("width", "500");  
        });  
    });  
    </script>  
    </head>  
    <body>  
    <img src="good-morning.jpg" alt="Good Morning Friends"width="284" height="213"><br>
    <button>Set the width attribute of the image</button>  
    </body>  
    </html>  
    

    Output :

    src="good-morning.jpg" alt="Good Morning Friends"width="500" height="213"

 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: