jQuery attr() set attribute via object

Introduction

Set width and height attributes of the image

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>//  w w w .  j a  va2  s .  c  o m
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("img").attr({width: "150", height: "100"});
  });
});
</script>
</head>
<body>

<img src="image4.png" alt="image4.png" width="100" height="100"><br>

<button>test</button>

</body>
</html>



PreviousNext

Related