Image width Property - Return the width of an image: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image

Description

Image width Property - Return the width of an image:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" src="http://java2s.com/resources/a.png" style="width:250px;height:300px;">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   www  .ja v  a2 s. c om
    var x = document.getElementById("myImg").width;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials