The attr() is a Jquery HTML/CSS Method. It is used to set or return attributes and values of the selected elements. When this method is used to return the attribute value, it returns the value of the FIRST matched element. When this method is used to set attribute values, it sets one or more attribute/value pairs for the set of matched elements. The parameters used in this method are attribute  - Specifies the name of the attribute, valueSpecifies the value of the attribute, function(index,currentvalue)Specifies a function that returns the attribute value to set.


$(selector).attr(attribute)  - Return the value of an attribute.

$(selector).attr(attribute,value) - Set the attribute and value.

$(selector).attr(attribute,function(index,currentvalue))  - Set attribute and value using a function.

$(selector).attr({attribute:valueattribute:value,...})  - Set multiple attributes and values.


	<!doctype html>
	<html lang="en">
			<meta charset="utf-8">

			<script src=""></script>
					  $("img").attr("width", "500");  
			<img src=""width="284" height="213"><br>
			<button>Set the width attribute of the image</button>  

In this code jquery is started with $(document).ready(function() . it is used to identify Document Object Model (DOM) is ready for JavaScript code to execute. The $("button").click(function(){ $("img").attr("width", "500"); when we click the button the image width changes to 500px.