Nrc
Nrc

Reputation: 9797

How to avoid img error icon

If you give an src and it cannot find the img it usually appears a square with a X. Is there any way to avoid that? I mean if it cannot find the img, just show nothing

You can check your solution here:http://jsfiddle.net/GmBax/

HTML:

<img src="1.png" width="42" height="42" >

Upvotes: 0

Views: 252

Answers (3)

Laksitha Ranasingha
Laksitha Ranasingha

Reputation: 4517

There's another option, you can load a default empty image on error. Ex: <img src="/img.jpg" onerror="this.src='/none.jpg'" />

Upvotes: 1

Dropout
Dropout

Reputation: 13866

Use the alt parameter for example.. You can either add a text or leave it empty.

<img src="1.png" width="42" height="42" alt="" />

Or handle it by some PHP or whatever you're using.

Upvotes: 0

Rachel Gallen
Rachel Gallen

Reputation: 28573

put in an "alt" and a "title" tag - this way if the image doesn't show, the alt text will show instead.

e.g.

<img src="1.png" width="42" height="42" alt="hello" title="hi">

Upvotes: 0

Related Questions