I'm trying to get the width and height of a div after it finishes loading by using javascript, but it's getting the width and height of the div BEFORE the image finishes loading. What can I do to fix this?
<script type = "text/javascript">
var width = document.getElementById("image").offsetWidth;
var height = document.getElementById("image").offsetHeight;
alert(width+":"+height);
</script>#image {
border: 1px solid red;
width: 50%;
}<div id = 'image'>
<img src = 'http://exmoorpet.com/wp-content/uploads/2012/08/cat.png'>
</div>Result:
634:2
Expected Result:
634:(More Than 2 Pixels)
 
     
     
    