I have a function that shows an image based on the user input by modifying the URL. When that image isn't found the console throws a 404 error.
What I'am trying to do is :
If that error happens , I want to write "Sorry , we could not find a company with that name" but what I did doesn't seem to work because my IF statement might be wrong , but I dont know what element I should be comparing the error 404 to???
This is Javascript :
let companyImageLink = document.getElementById("companyImage");
function changeLogoImage(str)
{
companyImageLink.src = "https://logo.clearbit.com/" + str + ".com"
if (companyImageLink.src === 404 || companyImageLink.src === 404 )
return searchedName.innerHTML = "Sorry , we could not find a company with that name"
}
This is HTML :
<div id="companyLogo" style="visibility : hidden;">
<div id="companyName" style="font-size: xx-large;"></div>
<div><img src="" style="height: 120px; width: 120px;" id="companyImage"></div>
</div>