I would like to prevent the default icon from appearing when an image is not found in an element < img >
. The text of the alt property does not matter to me as much but if I can also prevent it from coming out much better.
This is my element (the src property is set dynamically):
<img id="img_id" alt="0">
And this is how it looks without images and with images
Would anyone know how to do this?
Imagining you have multiple images with a class. It is possible to hide them using the event
error
with jQuery:As you can see, the second image comes from an invalid source. Now notice how I hide it using the event
error
:Or maybe you prefer to replace the image with a placeholder to keep the structure:
I'm using an inline placeholder, but you can change it to whatever image you deem necessary.
you can try with
onerror
Hello, you could use something like this:
For more details of the onerror I suggest you review this: OnError