Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Title of the Document</title> <style> img { margin: 20px; } </style> </head> <body> <div>Click on img to see the result</div> <script> let img = document.createElement('img'); img.id = 'imgId'; img.src = 'https://pbs.twimg.com/profile_images/1144166476682813440/o23kohmr_400x400.png'; document.body.appendChild(img); img.addEventListener("click", imgSize); function imgSize() { let img = document.getElementById('imgId'); //or however you get a handle to the IMG let width = img.clientWidth; let height = img.clientHeight; alert("Original width=" + width + ", " + "Original height=" + height); } </script> </body> </html>