anson920520 anson920520 - 1 year ago 67
jQuery Question

Javascript : Check <img> is empty generate by for loop and if true do something

For instance we have something like below, which is generate brunch of

with different src :

//the for loop is not important but just giving you some idea

<img class="emptyPic result-image" src="{{picURL}}"/>

and I'd like to check every
onload, if it's src is empty like
<img src=""/>
, i would like to do something, but in the example just make it
first. So i tried something like below with JQuery.

if($(this + ".result-image").attr('src')){
($(this + ".result-image").css("display","none")

i had put the if statmenet above into the for loop already and it should do the job but what is it not working?

Answer Source

You can use pure CSS:

img[src = ''] {display:none;}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download