Return the width of an <img> element: - Javascript CSS Style Property

Javascript examples for CSS Style Property:width

Description

Return the width of an <img> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="http://java2s.com/resources/c.png" style="width:100px;height:132px;">
<br>

<button type="button" onclick="myFunction()">Return width of image</button>

<script>
function myFunction() {/*from   w w w  .  j  ava  2  s.c om*/
    console.log(document.getElementById("myImg").style.width);
}
</script>

</body>
</html>

Related Tutorials