I need to call a method after an image has been loaded and fully rendered (appending it to the dom) in the browser.
In the following example window.onload fire only once, and now after pressing the button.
Any idea how to solve this/
http://jsbin.com/pisuzifofabo/1/
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
window.test = function (){
var body = document.getElementsByTagName('body')[0];
body.innerHTML += '<img id="c" src="http://upload.wikimedia.org/wikipedia/commons/3/3c/Ilc_9yr_moll4096.png" height="50" width="50"></img>'
};
window.onload = function() {
alert("load an rendered main");
// call my method
};
$('img').load(function(){
alert('loaded and redered');
});
</script>
</head>
<body>
<img id="a" src="http://upload.wikimedia.org/wikipedia/commons/3/3f/Fronalpstock_big.jpg" height="50" width="50"></img>
<img id="b" src="http://upload.wikimedia.org/wikipedia/commons/e/e3/Big-Bend-NP.jpg" height="50" width="50">
</img>
<button id="btn" onClick="window.test();"> click me</button>
</body>
</html>