It often happens that we allow users to upload a profile pic. But all the users do not upload a pic. Thus either we have to copy the same template image for all users or we get a broken image in the page. To fix this, use onerror code.
Approach 1 - Hide the image if no image is available.
onerror="this.style.display='none'"
Approach 2 - Use a template / filler image.
onerror="this.src='fallback-img.jpg'"
Comments