Tejas Agarwal
Tejas Agarwal

Reputation: 1

How to remove image tag if no image is loaded at the time of page creating

$image ='< img src="http://xyz.com/'.$add_image4.'" class="magnify" alt="/>';                                       

& if $add_image4 is empty,blank image still shows how do I remove it?

Upvotes: 0

Views: 206

Answers (2)

Beetroot-Beetroot
Beetroot-Beetroot

Reputation: 18078

Here's how to do it in jQuery :

$(function() {
    $("img.magnify").on('error', function() {
        $(this).remove();
    });
});

As written, all img nodes with class="magnify" will be removed if they fail to load.

The "img.magnify" selector can be adjusted to address more/less/different img nodes as required.

Upvotes: 0

Arun Jain
Arun Jain

Reputation: 5464

You can use this one:

<img src="http://theglenbot.com/a-broken-image.jpg" onerror="this.parentNode.removeChild(this);" />

Ths post might help you.

Upvotes: 1

Related Questions