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

If my image doesnt contain a src then i want to hide it using visibility hidden:<img border="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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745631261a4637122.html

相关推荐

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

    If my image doesnt contain a src then i want to hide it using visibility hidden:<img border="0&

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信