I have multiple images on a page and this code:
//main image
<img src="/my_image.png" id="main_img" />
//other images
<img .... onclick="setMainImg(this)" />
<button onclick="getSize()">get size</button>
//js, at the bottom
var mainImg = document.getElementById("main_img");
function getSize() {
console.log(mainImg.width + "x" + mainImg.height + "\r\n");
}
When the page loads, it prints something like 33x16
After I click on different images:
//js
function setMainImg(img) {
mainImg.src = img.src;
}
it begins printing the corrent values in the console:
448x354
and something like this. Even when I click the same first image(!), it prints a different, 10 times bigger, size.
Why? How to fix this?