I have an element and I\'m changing its src attribute. The element has an onload handler function attached. Each time i ch
To add to Matt Ball's answer, consider img.onload instead of img.addEventListener().
var photo = document.getElementById('image_id');
var img = new Image();
img.onload = myFunction;
img.src = 'http://newimgsource.jpg';
photo.src = img.src;
img.onload is easier to read and works better across user agents.