Make sure 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 that does not work.
if($('div.previewWrapper div.previewContainer img').attr('src') == '') {
alert('got me');
}
Someone can tell me what I am missing. What makes the click event work when src is empty.
THX
+5
4 answers
Please check it. Seems to work here
<div class="previewWrapper" id="thumbPreview3">
<div class="previewContainer">
<img src="" class="photoPreview" data-width="" data-height=""><span>3</span>
</div>
</div>
<input type="button" id=click value =" Click me" />
$(function () {
$("#click").click(function () {
if ($('div.previewWrapper div.previewContainer img').attr('src') == '') {
alert('got me');
}
});
});
+1