Skip to content Skip to sidebar Skip to footer

Remove Bootstrap's Carousel Item If Image Not Found

when the page loads, if the image returns a 404 not found error I would like to remove the wrapping div.item so the carousel continues as if.. how can I achieve this? this was my

Solution 1:

On the image tag you can add the onerror event

<img src="404imagegoeshere" onerror="functionToRemoveWrapping(this)">

Then on your function you can do something like this

    <script>
         function functionToRemoveWrapping(image) {
           setTimeout(function(){
             $(image).parent().remove;
           }, 2000);    
         }
    </script>

The 2000 value is in miliseconds.


Post a Comment for "Remove Bootstrap's Carousel Item If Image Not Found"