Javascript DOM CSS Style width Property get

Introduction

Return the width of an <img> element:

alert(document.getElementById("myImg").style.width);

View in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="image1.png" style="width:100px;height:132px;">
<br>

<button type="button" onclick="myFunction()">Return width of image</button>
<p id="demo"></p>
<script>
function myFunction() {/*from   w w  w  .  j  a v a2  s. c om*/
  document.getElementById("demo").innerHTML = document.getElementById("myImg").style.width;
}
</script>

</body>
</html>



PreviousNext

Related