Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide all children div except a specific one with jQuery?

Tags:

jquery

<div id="target">
    <div id="exclude"></div>
    <div></div>
    ...
</div>

$('#target').children().hide(); will hide all.

like image 721
user198729 Avatar asked Jan 08 '10 05:01

user198729


1 Answers

What you're wanting to do is hide all of the siblings of a particular element. That's relatively simple with jQuery using the .siblings method:

​$("#exclude").siblings().hide();​​​​

This will hide all elements on the same level, in the same parent element.

like image 132
Sampson Avatar answered Oct 08 '22 09:10

Sampson