my Image tag
<img src="https://img.youtube.com/vi/Q9p-UGqlRMg/mqdefault.jpg">
i tried this ( this works with the rest of 404 image URLs but not with youtube thumbnail url )
$('img').on('error', function() {
$(this).attr('src', 'http://i.giphy.com/9J7tdYltWyXIY.gif'); // show a fallback image if there is an error
});
and
<img src="https://img.youtube.com/vi/Q9p-UGqlRMg/mqdefault.jpg" onError="this.onerror=null;this.src='https://placeimg.com/200/300/animals';">
I guess youtube already returning a default 404 image, that might be a reason.
2
Answers
you forget the extension file ??
try this
YouTube answers will not fire the onerror() function because YouTube sends image which shows the gray video icon. The approach, knowing dimensions of the returned image is to detect it and replace it with our backup image. Try running snippet below:
Or to handle every image in the time of loading it instead of waiting for all and iterating over them: