最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - hide image using jquery if it has no src - Stack Overflow

matteradmin5PV0评论

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?

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?

Share Improve this question asked Jul 19, 2012 at 10:56 SOLDIER-OF-FORTUNESOLDIER-OF-FORTUNE 1,6545 gold badges39 silver badges68 bronze badges 1
  • 2 Please note that if your img tag has width & height attributes it will still occupy some space when using visibility:hidden. Most of the answers will make your img display:none; – Bob Commented Jul 19, 2012 at 11:03
Add a ment  | 

5 Answers 5

Reset to default 4
$('img').filter(function(index){return $(this).attr('src')==='';}).hide();
$(document).ready(function(){
  $("img").each(function(){
     (!this.src || $(this).prop("src")) && $(this).hide();
  });
});

Thanks to @GeorgeMauer

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

Try this without any loop:

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

DEMO

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

That will hide the element.

Post a comment

comment list (0)

  1. No comments so far