If my image doesnt contain a src then i want to hide it using visibility hidden:
<img border="0" src="" style="cursor:hand;cursor:pointer;" id="EntityPic543">
How can i do this with jquery?
$(document).ready(function(){
$("img").each(function(){
(!this.src || $(this).prop("src")) && $(this).hide();
});
});
Thanks to @GeorgeMauer
jquery(this) just to get an src attribute?attr('src') is undefined (going through the DOM will). If you really want to keep this form then $(this).attr('src')||'' will do it.$('<img>').attr('src')=="" will return false so the image will not hide jsfiddle.net/LafSw!this.src && $(this).hide() will not work if the image already has attribute src="" jsfiddle.net/LafSw/2$('img').each(function() {
!this.src && $(this).hide()
});
imgtag haswidth&heightattributes it will still occupy some space when usingvisibility:hidden. Most of the answers will make yourimgdisplay:none;