Reputation: 13049
$("#result").html($('[contenteditable]').text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="scorer">
<div>
<div contenteditable>1</div>
<div contenteditable>2</div>
</div>
</div>
<div>
<div contenteditable>3</div>
<div contenteditable>4</div>
</div>
<hr />
<div id="result">
result
</div>
How can I select contenteditable elements which do not have a parent up the chain of "scorer" in CSS or jquery.
Result should be 34.
Thanks!
Upvotes: 0
Views: 99
Reputation: 28338
Try to fetch all except for children of scorer:
$('div[contenteditable]').not('.scorer div');
Upvotes: 1
Reputation: 115
Just to give you a different approach which is the one i find more easier to read
$('.result').html($('div:not(.scorer) [contenteditable]').text());
Upvotes: 0
Reputation: 4645
Try not()
$("#result").html($('[contenteditable]').parent().not('.scorer div').text());
Upvotes: 1
Reputation: 25527
You can use filter function for this
var result = $("div[contenteditable]").filter(function () {
return $(this).closest(".scorer").length == 0
}).text();
Upvotes: 2
Reputation: 14348
You can use not()
function like this .not('.scorer div')
$("#result").html($('[contenteditable]').not('.scorer div').text());
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="scorer">
<div>
<div contenteditable>1</div>
<div contenteditable>2</div>
</div>
</div>
<div>
<div contenteditable>3</div>
<div contenteditable>4</div>
</div>
<hr />
<div id="result">
result
</div>
Upvotes: 3