如果容器拥有某个类的div,则从容器中删除imgs

我有divs的div。但是,这些div中的一些也有一个跨度作为div中的第一个元素。此跨度表示此div中imgs的“标签”。 我有一个脚本,如果我按住alt并点击这个“数据包”div,它将被删除。但是,我不想删除其中包含标签的数据包。对于那些,只需删除内部的imgs就足够了。 我一直无法建立这种逻辑。同样,为了通过单击并按住alt键来传达删除功能,我尝试将css属性更改为某些颜色作为提示。这也是行不通的。
$(".Card_Packet").click(function (e) {
    if (e.altKey) {

        $(this).live('hover', function(event) {
            if (event.type === 'mouseover') {
                $(this).css({
                    'border-color': 'red'
                });
            }
            else {
                $(this).css({
                    'border-color':'black'
                });
            }
        });

        if ($(this).find('Sect_Header')) { //if the div contains the label, remove only the images. Otherwise, remove the whole thing.
            $(this).remove('img');
        } else {
            $(this).remove();
        }
    }
});
我确信它与我的操作顺序有关。     
已邀请:
if($(this).children(":first").is("span")){ //If the div contains the label, remove only the images..
   $(this).find('img').remove();
}else{ //Otherwise remove packet div
   $(this).remove();
}
    
这是一些工作代码:
$(".Card_Packet").click(function (e) {

    if (e.altKey) {

        if ($('.Sect_Header', this).length > 0) { 
            //if the div contains the label, remove only the images. 
            //   Otherwise, remove the whole thing.

            $('img', this).remove(); //removes the images

        } else {

            $(this).remove(); //removes the whole thing

        }

    }

});
小提琴:http://jsfiddle.net/maniator/xwmwD/     
你正在做的将删除整个div。只需这样做只删除任何div中的图像:
$('select-your-div img').remove();
    

要回复问题请先登录注册