jQuery attr() get attribute value

Description

jQuery attr() get attribute value

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 av  a  2  s.  com*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    document.getElementById("demo").innerHTML = "Image width: " + $("img").attr("width");
  });
});
</script>
</head>
<body>

<p id="demo"></p>
<img src="image4.png" alt="image4.png" width="284" height="213"><br>

<button>Return the width of the image</button>

</body>
</html>



PreviousNext

Related