How can I remove a blank image container if the image’s source is unavailable please? I would only like the image to appear if its source is available. Otherwise, I don’t want anything to appear, including the blank container.
HTML image syntax:
<img src="url" alt="some_text">
You are able to do this using JavaScript and the
errorevent on the img tag.For example:
(Oops, sorry @JosephSilber, modified my example to be a bit different ;-))
Your best bet would be using server-side processing if you know that your image isn’t going to be available. If you’re intentionally leaving the
srcblank, for example, you can do something like this in PHP: