-1

Is it possible to check with jQuery if in an image tag an image url is inside and if there is not that the img tag will not show?

HTML now:

<div id="slide">
    <img src="http://www.url.com/.jpg" alt="" />
    <img src="http://www.url.com/.jpg" alt="" />
    <img src="" alt="" /> - here is no img url so this one must be deleted
</div>

How can I do this?

4

3 回答 3

2

Target images with an empty source, and remove them :

$('#slide img[src=""]').remove();

or the filter() method :

$('#slide img').filter(function() {
    return ! $.trim( this.getAttribute('src') ).length;
}).remove();
于 2013-08-02T10:05:32.313 回答
1

Try like this

$("img").each(function(){
     if($(this).attr("src") == "") {
           $(this).remove();
      }
});
于 2013-08-02T10:06:00.767 回答
1

Works:

$('#slide').find('img[src=""]').remove();
于 2013-08-02T10:06:17.357 回答