How to use HTML Attr Method in JQuery

This article describe about HTML Attr Method in JQuery.
  • 1891

HTML attr() method in jQuery

The arre() method is return the value of selected elements and sets the attribute value.

 Attr method is process to work different parameters.




<!DOCTYPE html>



<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">

    $(document).ready(function ()


        $("button").click(function ()


            $("img").attr("width", "150");






<img src="Blue hills.jpg" alt="Pulpit Rock" width="284" height="213" />

<br />

<button>Set the width attribute of the image</button>





Output2 After click this button


Using a Function

We use a function to set the attribute value for the selected elements.


$(selector).attr({attribute:value, attribute:value, ...})

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2018 DotNetHeaven. All rights reserved.