This question has already been answered:
- Show pictures by size div 1 answer
Why the alert('imageh:'+imageheight);
although there is an alert('result:'+result);
before it alert('result:'+result);
?
The main question as a result
to bring to the imgeheight
?
var result = 1; for (var i = 1; i <= result; i++) { var img = document.createElement('img') img.src = "https://pixabay.com/static/uploads/photo/2015/10/01/21/39/background-image-967820_960_720.jpg"; img.onload = function() { $('.left').append(this); result = this.height; alert('result:' + result); } var imageheight = result; alert('imageh:' + imageheight); }
img { width: 10%; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="left"></div>