下面刪除特定父的孩子是我的HTML結構從選擇
<div class="parent">
//many other elements
<div class="child">
<div class="grandchild"></div>
</div>
</div>
我要選擇除了內部的子元素
我想下面的其中一個沒有工作
裏面父的所有元素$(".parent *:not(.child *)")
我該如何選擇?
下面刪除特定父的孩子是我的HTML結構從選擇
<div class="parent">
//many other elements
<div class="child">
<div class="grandchild"></div>
</div>
</div>
我要選擇除了內部的子元素
我想下面的其中一個沒有工作
裏面父的所有元素$(".parent *:not(.child *)")
我該如何選擇?
試試這個:
$('.parent *').filter(function(){
return $(this).parents('.child').length === 0;
});
這將選擇內部.parent
所有元素,除了那些誰也爲兒童/的.child
$('.parent *:not(.child, .child *)')
子兒試試這個。
雖然也許你想這樣的:
$(".parent > *:not(.child)")
試試這個: 會選擇所有的父類.parent下與類兒童開始DIV。
$('.parent div[class^="child"]')
$('.parent *').not('.child *')
我要選擇內 子元素除外父裏面所有元素
你可以使用find方法。 它會發現所有的子孫/兒童除外(「母公司*」)的內部類child
$(".parent").find("*").not($(".child").children()).each(function(){
alert($(this).prop("class"));
});
'$'孩子是這個試過了嗎? – guradio
檢查此解決方案http://stackoverflow.com/questions/1125700/how-do-i-use-jquery-to-select-all-children-except-a-select-element –