Reputation: 406
I want a part of my page not to be parsed by the jQuery Selector.
In the example below, is there a way to get all the ".module" elements but exclude the one under the div which has the class "exclude" ?
Moreover, can we do with Jquery something like "please do not parse this area". For example, I have a page which has a div(#huge) with a HUGE html content, is there a way for Jquery to ignore this div(#huge) ?
For example, I have this structure:
<div id="page">
<div class="exclude">
<div class="module"></div>
<!-- HERE HUGE HTML -->
</div>
<div>
<div class="module"></div>
<div class="module"></div>
</div>
</div>
Upvotes: 0
Views: 164
Reputation: 1596
$modulesNotTheHugeOne = $(".module").not("#huge");
selects all with class module
but not the one with id huge
Upvotes: 0
Reputation: 382514
In your precise case, the key is to look only in the right divs.
You would start by making the searchable collection
var $good = $('#page>div:not(.exclude)');
And all your queries would be built as $(yourquery, $good)
:
var $mymodules = $('.module', $good);
Demonstration (open the console)
Note that when looking for an element by its id, it still would be more efficient to use $('#theid')
rather than $('#theid', $good)
.
Upvotes: 1
Reputation: 93003
$modules = $('div:not(".exclude") > .module');
http://api.jquery.com/not-selector
Upvotes: 3