SOLDIER-OF-FORTUNE
SOLDIER-OF-FORTUNE

Reputation: 1654

hide image using jquery if it has no src

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?

Upvotes: 0

Views: 2893

Answers (5)

Imdad
Imdad

Reputation: 6042

$(document).ready(function(){
  $("img").each(function(){
     (!this.src || $(this).prop("src")) && $(this).hide();
  });
});

Thanks to @GeorgeMauer

Upvotes: 2

Andreas Nilsson
Andreas Nilsson

Reputation: 231

$("#EntityPic543").css("visibility", "hidden"); 

That will hide the element.

Upvotes: 0

George Mauer
George Mauer

Reputation: 122132

$('img').each(function() { 
  !this.src && $(this).hide()
});

Upvotes: 1

Mukesh Soni
Mukesh Soni

Reputation: 6668

$('img').filter(function(index){return $(this).attr('src')==='';}).hide();

Upvotes: 4

thecodeparadox
thecodeparadox

Reputation: 87073

Try this without any loop:

$('img[src=""]').hide();

DEMO

Upvotes: 0

Related Questions