[英]select outer and child ,without inner div
<div class="outer">
<div class="inner">
<div class="child">
</div>
</div>
</div>
I want to select outer and child only. 我只选择外部和子级。 But selecting outer will include inner and child.
但是选择外部将包括内部和子级。 If I used
not
ie $(".outer , .child").not(".inner")
, it will exclude child too. 如果我
not
使用$(".outer , .child").not(".inner")
,它将也排除child。
ie I want to select outer and child ,without inner . 即我要选择外部和外部的孩子 。
As you can't select it perfectly using a single query, you'd be better taking it out of the DOM (You can't get the results you want as is
) 由于您无法使用单个查询完美地选择它,因此最好将其从DOM中删除(您无法
as is
获得所需的结果)
//So clone it it from the dom
var outer = $('.outer').clone();
var child = $('child').clone();
// Remove the `Inner` from the cloned version
outer.find('.inner').detach();
// Add the child to the outer.
outer.append(child);
您可以使用:
$('.outer, .outer :not(.inner)')
只需使用.outer,.child
:
$('.outer,.child')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.