Donate

Check If Images Are Not Rendered Correctly To The Browser Using JavaScript

Hello,
Here's a function to hide divs if it's children specifically images does not render correctly to the browser or an error has occured.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
function ImageDivHandler() {    
   $("div.gallery").each(function () {  
     if ($(this).children().length == 0) {  
       $(this).hide();  
     }  
     else {  
       var img = $(this).find(".image-responsive");  
       if (img != null || img != undefined) {  
         imgSrc = $(this).find(".image-responsive").attr("src");  
         if (imgSrc == "" || imgSrc == null || imgSrc == "null") {  
           $(this).find(".image-responsive").closest("div.gallery").hide();  
         }  
         else {  
           $(this).find(".image-responsive").error(function () {  
             $(this).closest("div.gallery").hide();  
           });  
         }  
       }  
     }  
   });  
 }  
Note: I may change the logic from time to time depending on the layout of the image container. But the concept is pretty much the same.
Greg

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

TypeScript Error Or Bug: The term 'tsc' is not recognized as the name of a cmdlet, function, script file, or operable program.