Is it possible to measure the width of an image loaded by user click in Javascript? I need the width in order to adjust the position of a button next to the image.
Here is the code I am using:
document.getElementById('preIMG').addEventListener("load", adjustButtonPosition);
function adjustButtonPosition(){
var imgWidth = document.getElementById('preIMG').clientWidth;
var imgWidPos = document.getElementById('picture_preview').clientWidth - imgWidth + 15;
document.getElementById('gear_butto').style.right = (imgWidPos*0.5) + "px";
}
Additional note: The user can view multiple images and it seems that the addEventListener
only works the first time the side is loaded.