Reputation: 7812
I have this html :
<div id="container1">
<div id="container3">
<div class="item"></div>
<div class="item2"></div>
</div>
<div class="item"></div>
<div class="item2"></div>
<div id="container2">
<div class="item"></div>
<div class="item"></div>
<div class="item2"></div>
</div>
<div>
With jQuery, is there a (simple) way to search for divs with .item
, but masking all the results inside #container2
?
Ideally I'd like something like $(#container1).mask('container2').find('.item')
, i.e. a transparent solution that you could use with any other query, without knowing that you are using it. For example :
// where queryExcludingContainer2 could be `$(#container1).mask('container2')` if the `mask` function existed
queryExcludingContainer2.find('.item')
queryExcludingContainer2.find('.item2')
Is there such a "masking" feature?
Upvotes: 1
Views: 60
Reputation: 5224
You can use the ":not" selector http://api.jquery.com/not-selector/
$('.item:not(#container2 *)')
Upvotes: 1
Reputation: 2394
You mean something like this?
$('div').not('#container2').children('.item')
For more Information:
jQuery API Documentation of not()
Upvotes: 2
Reputation: 4585
I think you need to use children()
Example JS Fiddle.
$("#container1").children(".item").css('font-style', 'italic');
Upvotes: 1
Reputation: 893
I think, you can use space-bar
like this:
$('#container1 .item')
And, if .item
element was under the #container1
directly, you can also use this:
$('#container1 > .item')
Upvotes: 0