Javascript examples for DOM HTML Element:Image
Image naturalWidth Property - The difference between the naturalWidth property and the width property:
<!DOCTYPE html> <html> <body> <img id="myImg" src="http://java2s.com/resources/a.png" style="width:500px;height:98px;"> <button onclick="myFunction()">Test</button> <p id="demo"></p> <p id="demo2"></p> <script> function myFunction() {//from w ww . ja v a 2 s . c o m var x = document.getElementById("myImg").naturalWidth; document.getElementById("demo").innerHTML = "The original width of the image is: " + x + " pixels"; var y = document.getElementById("myImg").width; document.getElementById("demo2").innerHTML = "The 'styled' width of the image is: " + y + " pixels"; } </script> </body> </html>