08 12 / 2010

HOW TO: Replacing Broken Images with JS

I was recently looking for a quick way to insert a backup image in place of a missing/broken image. I ran into this bad boy that seems to do the trick.

<img src=“your-image-path.jpg” onerror=“this.onerror=null;this.src=’your-backup-image.jpg’;”/>