<img src="images/business-card.webp" one rror="this.onerror=null; this.src='images/business-card.jpg' " >
I want to write this feature from within js file. How can i do it ?
CodePudding user response:
First, create the image in javascript:
var image = document.createElement("IMG");
document.body.appendChild(image);
image.src = "images/business-card.webp;
image.class = "m-auto img-fluid";
Now, add an one rror function:
blah.onerror = function(){this.onerror=null; this.src='images/business-card.jpg'};