JavaScript img object property: naturalWidth
[this page | pdf | back links]
The naturalWidth property of the JavaScript
DOM object
corresponding to the HTML <img> element returns
the original width of the image underlying the <img> element.
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
original image (width x height of 32 x 32): <img src="NematrianLogo.png"><br>
resized image (to width x height of 23 x 40): <img id="element" src="NematrianLogo.png" style="width: 23px; height: 40px"><br><br>
naturalWidth of resized version: <b id="x2"></b>
<script>
var x = document.getElementById("element");
document.getElementById("x2").innerHTML = x.naturalWidth;
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)