What should I use instead of the deprecated `onerror` attribute?

error-handling, fallback, image, placeholder

Solution

I think that was a mistake.

WHATWG still mention `onerror` in their HTML living standard specification.

Also, `onerror` attribute on `img` elements is not included in their obsolete features list.

Problem

On my images I'm setting the `onerror` attribute so that a placeholder is used in case the image is not available for some reason: ``` <img class="article-img" src="path-to-image.jpg" alt="some description" onerror="this.src='/images/fallback.png'" > ``` Now, it looks like `onerror` has been deprecated, but I couldn't find any good source on what would be the suggested alternative way of handling the error (possibly in a similarly compact fashion). It would be also interesting to know why it was deprecated.

Original source