anson920520 anson920520 - 4 months ago 8x
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?


You can use pure CSS:

img[src = ''] {display:none;}