<div class="container" id = "0" >
<div class="x" id = "1">
<div id = "2">
<p id = "3">
<span id = "4" >text</span>
</p>
<div>
</div>
<div id="5">
<div id="6">
<p id="7">
<span class="x" id="8" >text</span>
<span id="9">text</span>
</p>
<div>
</div>
<div>
Can you help me to select all the elements :
Looking at the HTML above; it should select the elements 5,6,7 and 9
Element 8 has class "X"
I have this selector but it keeps selecting the descendants (deep children) of element with class "X"
var elements = $('.container').find().parents(':not(.X)').andSelf().filter(':not(.X)');
This should do it:
$('.container').find(':not(.x):not(.x *)');
Edit: Reverted to first revision again. I thought it did not work this way, but you have an error in your HTML which makes #1
parent of all elements, so none is selected.
<div class="container" id = "0" >
<div class="x" id = "1">
<div id = "2">
<p id = "3">
<span id = "4" >text</span>
</p>
<div> <!-- <-- must be a closing div tag -->
</div>
<div id="5">
<div id="6">
<p id="7">
<span class="x" id="8" >text</span>
<span id="9">text</span>
</p>
<div> <!-- <-- must be a closing div tag -->
</div>
<div> <!-- <-- must be a closing div tag -->
using wildcards either
$(".container :not(* .x)")
or
$(":not(* .x)", ".container")
may work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With