2013-07-18 140 views

回答

1

您可以使用:not组合:has

Live Demo

$("div:not(:has(iframe))").remove(); 
+0

谢谢!它适用于iframe和'iframe':) – Ortzi

+0

@Royi Namir:为什么?这是一个元素,而不是一个字符串。 – BoltClock

+0

@ user2595583:是的,这很奇怪,但我发布了一个探索问题 - http://stackoverflow.com/questions/12475595/why-do-the-not-and-has-selectors-allow-quoted-arguments – BoltClock

0

我想删除所有有一个iframe作为一个孩子

我一直使用的元素一个过滤器:

$('div').filter(function(i,el) { 
    return $(el).find('iframe').length; 
}).remove(); 

反其道而行之:

$('div').filter(function(i,el) { 
    return !$(el).find('iframe').length; 
}).remove(); 
0
var $divsWithoutIframeChilds = $('div').filter(function(i, el){ 
    return $(el).find('iframe').length < 1; 
}); 

$divsWithoutIframeChilds.remove();