Reputation: 1030
I want to hide all elements except for an element with a specific class AND all elements inside this.
right now im using
$("body").not(".embedded").hide();
But it also hides the elements inside my .embedded element.
I appreciate every help.
Upvotes: 0
Views: 43
Reputation: 2141
Here you are:
$('body :not(".class2")').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span class="class1">11111</span>
<span class="class2">
10
<span class="class21">11</span>
<span>12</span></span>
<span class="class1">11111</span>
Hope this helps.
Upvotes: 1
Reputation: 30587
Use *
and space
to indicate all direct/nested children. Also, for the initial selector, use body *
to indicate all children before the not()
filtering
$("body *").not(".embedded, .embedded *").hide();
Upvotes: 2