On my website I have empty image frames like this when the load resource fails because it doesn't exist:
This is an example image tag:
<img class="thumbnail" src="{{event.venue.icon}}" id="thumbnail">
How can I simply remove these empty frames?
On my website I have empty image frames like this when the load resource fails because it doesn't exist:
This is an example image tag:
<img class="thumbnail" src="{{event.venue.icon}}" id="thumbnail">
How can I simply remove these empty frames?
Check out onerror event, when image is loaded hide it if loading fails:
<img src="someimage.jpg" onerror="this.style.display='none';" />
Bind to the error event for the images and from within that method you can remove the containers for any images that fail to load. Here is an example, but post your code if you want something more specific:
$('.yourImageSelector').error(function() {
$(this).parent().remove();
});
Bind error
event on img tag like this,
$(document).ready(function(){
$('#myImg').on("error", function() {
$(this).remove(); // Execute with commenting this line and see the result
console.log(document.querySelector('img'));
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img id="myImg" src="compman.gif" alt="Computerman" width="107" height="98">
Comment $(this).remove();
and execute, you will get the "Computerman" as the text alternative specified by alt
attribute also the img
element in the console as result.