In this example, we’ll learn How to find the height of an image in JavaScript.
HTML + JavaScript Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<!DOCTYPE html> <html> <body> <img id="myImg" src="compman.gif" width="107" height="98"> <p>Click the button to display the height of the image.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x = document.getElementById("myImg").height; document.getElementById("demo").innerHTML = "Height: "+x; } </script> </body> </html> |
Output: