Answers for "is there an opposit of onerror html"

0

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);
    }
Posted by: Guest on August-28-2021

Browse Popular Code Answers by Language