最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论