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)