Categories
html image javascript jquery

Check if img src is empty using jQuery

I have the following HTML:

 <div class="previewWrapper" id="thumbPreview3">
<div class="previewContainer">
<img src="" class="photoPreview" data-width="" data-height=""><span>3</span>
</div>
</div>

And I have the following JQUERY which isn’t working.

    if($('div.previewWrapper div.previewContainer img').attr('src') == '') {
alert('got me');
}

can anyone advise what I’m missing.
What to get the click event to work when the src is empty.

thx

try this code:

$(document).ready(function(){
if ($("div.previewWrapper div.previewContainer img[src=='']").click(function()){
alert('got me');
}
});