1
<a class="thumbnail-link" href="">
<div id="thumbnail-wrap" class="thumbnail-wrap">
<img width="600" height="360" src="image.jpg">
</div>
</a>

How do I show thumbnail-link div if there is image?

Opossite solution would be...

<script type="text/javascript">

jQuery(document).ready(function( $ ) {

    $(".thumb-summary").find("img[src='']").parent().hide();

});
</script>

But than, its visible on page load that it hides divs without image and looks bad. I want to make it only show images if it finds them, jquery way please.

1 Answers1

0

Initially hide all the parent element which is .thumbnail-wrap using CSS and later show elements which have an attribute value, use :not() pseudo-class selector to ignore all img tag with src empty.

CSS :

.thumb-summary .thumbnail-wrap{
   display:none;
}

JQUERY :

jQuery(document).ready(function( $ ) {
    $(".thumb-summary").find("img:not([src=''])").parent().show();
    // or 
    //  $(".thumb-summary .thumbnail-wrap:has(img:not([src='']))").show();
});


FYI : If you have access to backend code then add some class to the parent element based on src and add style to that particular class(for hiding).

Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188