I have a div that is armed by Javascript and a JSON, this puts an image that brings it from a server, the problem is that if the image is not, the div remains blank.
- UPDATE -
I do not have the URL in the database, it is assembled in a static way together with the element ID. I do not have access to the route, I just want to check if it exists I put the photo, if it does not exist I put a default one
for (var i = 0; i < data.features.length; i++)
{
var precio = parseFloat(data.features[i].properties.precio);
if (precio != '')
precio = '$' + precio.toFixed(0).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
else
precio = 'Sin precio';
h += '<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 propDetails"' +
'style="background-image: url(\'ruta/images/'+ data.features[i].properties.id +'/foto_principal.jpg\')">' +
'<img class="fav" src="../images/favorito.png">' +
'<div class="details">' +
'<p class="dom"><span>'+ precio +'</span><br>'+ data.features[i].properties.calle +'</p>' +
'</div>' +
'</div>';
}
To put this by default I tried to do this in CSS
.propDetails
{
background-image: url(../images/default.png);
}
You're not doing what I'm trying to do What can I implement?