is there an opposit of onerror html
var img = document.getElementById('img'); var imgURL = "/path/to/new_img.png"; img.addEventListener('error', refresh); img.addEventListener('load', refresh); // *** img.src = imgURL; function refresh(e) { img.src = imgURL; if (e.type !== "error") { img.removeEventListener('error', refresh); img.removeEventListener('load', refresh); }