tags:

views:

32

answers:

2
<div id="container">
<div id="specific_one">..</div>
...
</div>

I want to hide all children of #container except #specific_one, how to do that?

+4  A: 

have you tried something like:

$('#container *:not(#specific_one)').hide();

or

$('#container').children(':not(#specific_one)').hide();

and I think this one is faster...

$('#container #specific_one').siblings().hide(); //please comment on this guys...
Reigel
functional 'selecting' is always faster than doing it just with selectors. Functions like .not() just do an array slice, whereas ':not()' needs to traverse the DOM.
jAndy
ahh thanks for the info... cheers!
Reigel
(What's more, the non-standard jQuery selectors like `:not` mean the whole selector can't be handed off to the fast native selector engine in modern browsers with Selectors-API support. Doing negation in a separate filtering step with the `not()` method is typically faster.)
bobince
+2  A: 
$('#container').children().not('#specific_one').hide();
jAndy