I have the following javascript/jquery function that on click of a button it fills the div with id=test with an image.
document.querySelector('div#test').innerHTML = "<div class='position-relative slotpar'><div class='position-absolute'><img src='./Images/my-poster/slot.png' class='slotimg'></div></div>";
Right after in the same function I have the following code that reads the hight of the img element in the divs and passes it to the position-relativ div.
$(".slotpar").height($(".slotimg").height());
The function is not working properly though and I believe that the problem is that this code that passes the hight to the relative div does not wait for the document.querySelector('div#test').innerHTML to properly load the html and the images. I have tried using a timeout of 1 second and it works so I am prety sure the the problem is the one I mentioned.
Is there a way to wait for the html and the image to be completly loaded on click and then take pass the hight of the image to the relative div?
Please help me