Hello everyone I have been using StackOverflow for some time and always find the correct answer with the search box but this time I couldn't! that is why I ask for your help. I am sure the solution its simple but I I have done several test and I could fix my issue.
I want to make its if a image fails to load, change a text related to that image and make that text RED that is already working but caveman style, that why i need your help here
document.getElementById("0").onerror = function() {Fu0()};
document.getElementById("1").onerror = function() {Fu1()};
document.getElementById("2").onerror = function() {Fu2()};
function Fu0() {
document.getElementById("0").style.display = "none";
var x = document.getElementById("T0");
x.innerHTML = "ERROR";
x.style.color = "red";
x.style.fontWeight = "bolder"
x.style.backgroundColor="800000";
};
function Fu1() {
document.getElementById("1").style.display = "none";
var x = document.getElementById("T1");
x.innerHTML = "ERROR";
x.style.color = "red";
x.style.fontWeight = "bolder"
x.style.backgroundColor="800000";
};
function Fu2() {
document.getElementById("2").style.display = "none";
var x = document.getElementById("T2");
x.innerHTML = "ERROR";
x.style.color = "red";
x.style.fontWeight = "bolder"
x.style.backgroundColor="800000";
};
I have this more than 20 times on my HTML which means a crazy amount of lines I was thinking in a loop to run using (i) but I cannot manage to make it work.
I have try this and a few variation whit no success at all.
for (i = 0; i < 26; i++) {
document.getElementById(i).onerror = function() {Fu()};
}
function Fu() {
document.getElementById(i).style.display = "none";
var x = document.getElementById("T"+i);
x.innerHTML = "ERROR";
x.style.color = "red";
x.style.fontWeight = "bolder"
x.style.backgroundColor="800000";
};
I will really appreciate it if you can help me, Thanks in advance