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.
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
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(); }); } } } }); } |
Greg
Comments
Post a Comment