HTML ~ Hide broken images, or replace then gracefully
Kabue Charles

Kabue Charles @mckabue

About: Poet; Entrepreneur; Philosopher; Genius Lateral Thinker; Software Architect; Created Library.co.ke

Location:
Kenya
Joined:
Sep 27, 2017

HTML ~ Hide broken images, or replace then gracefully

Publish Date: Jun 20 '18
34 4
onerror="this.src='fallback-img.jpg'"
onerror="this.src='fallback-img.jpg'"
Enter fullscreen mode Exit fullscreen mode

Comments 4 total

  • Jip⚡️
    Jip⚡️Jun 20, 2018

    Wow, I had no idea img tags had an onerror attribute! Thanks!

    • Devin Handspiker-Wade
      Devin Handspiker-WadeJun 21, 2018

      Most JS events can be used as attributes. Usually not recommended; even in this case depending on the scale it may be better/cleaner to have a error handler listening for any image error.

      If you're interested is event attributes, Mozilla has some nice documentation on it: developer.mozilla.org/en-US/docs/W...

  • Mattia Astorino
    Mattia AstorinoJun 22, 2018

    Ther is an error in the inlined code.

    onerror="this.src='this.src='fallback-img.jpg'"

Add comment