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 :
0 Comment(s)