<div id="target">
<div id="exclude"></div>
<div></div>
...
</开发者_高级运维div>
$('#target').children().hide();
will hide all.
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.
I believe that $('#target > div').not('#exclude').hide()
should do what you want.
Or alternately if you want sub-children that are divs too, $('#target div').not('#exclude').hide()
Use the :not selector
$('#target').children().hide();
$('#exclude').show();
Have you tried using the "not" selector with the id that you want to exclude?
http://docs.jquery.com/Selectors/not#selector
Also, the obvious answer would be to follow it with a $('#exclude').show()
精彩评论