Horje
How to set Multiple Image if First Image is error

Here is simple way to set multiple Image if First Image is error.

This function is called Fallback.


Image Fallback Function HTML

See the Example.

You can add multiple image using 'https://cdn-icons-png.flaticon.com/128/6912/6912971.png' into the code.

index.html
Example: HTML
<script>
function incrementFallbackSrc(img, srcs) {
    if (typeof img.fallbackSrcIndex === 'undefined') img.fallbackSrcIndex = 0;
    img.src = srcs[img.fallbackSrcIndex++];
}    
</script>

<img
src="https://cdn-icons-png.flaticon.com/128/8067/8067997.png"
onerror="javascript: incrementFallbackSrc(this, ['https://cdn-icons-png.flaticon.com/128/8067/8067999.png',
'https://cdn-icons-png.flaticon.com/128/6912/6912971.png'
])">

Output should be:





html image error

Related Articles
How to set Multiple Image if First Image is error HTML Image Tutorial


Read Full:
HTML Image Tutorial
Type:
Develop
Category:
Web Tutorial
Sub Category:
HTML Image Tutorial
Uploaded by:
Admin
Views:
101