1
I am using the JSON database and I have a problem: when there is an image in JSON, instead of the tag <img>
does not appear, it appears as if the image of that error:
Is there any way when the src
not found in JSON, tag img
not show up?
Code:
var image3: obj.imagem3;
var image: obj.imagem;
$("#imagemareas3").attr("src", this.image3);
$("#imagemareas").attr("src", this.image);
<img class="imageminfo" id="imagemareas" src="">
<img class="imageminfo" id="imagemareas3" src="">
JSON:
[
{
"titulo": "Exemplo",
"imagem": "",
"imagem3": "",
"id": 0
}
]
Yes, do not insert the image on the page\(ツ)/¯
– Woss
@Andersoncarloswoss but I need it because in other json arrays there already has an image but in case it doesn’t have an image it disappears
– David Mv
Exactly. It makes no sense for you to insert the element
<img>
on the page if thesrc
will be empty.– Woss
If you’re interested, did you know that you can style and customize an image that doesn’t load? It does not need to appear so you can treat the image that fails to load, read more here https://answall.com/questions/321138/comort-do-um-stilo-para-broken imagem-quando-imagem-n%C3%A3o-load
– hugocsl