How to fade all divs in a container except one with jQuery?
문제
I've got this:
$("#id").click(function() {
$('.swoosh div').fadeOut('fast', function(){
$('.template').fadeIn('fast');
});
});
.swoosh
is the container div, and
.template
is the div that i want to remain when i click on #id
, while all other divs inside .swoosh
disappear.
I feel a bit silly, but I've played around for ages to no avail. Please help a brother out.
해결책
You can probably use the not
[doc] selector
$("#id").click(function() {
$('.swoosh div:not(.template)').fadeOut('fast');
});
다른 팁
$('.swoosh div[class!="template"]').fadeOut('fast');
$("#id").click(function() {
$('.swoosh div').fadeOut('fast');
$('.template').fadeIn('fast');
});
Since you are fading out the container DIV it seems logical that all elements within that DIV are also fading out. So, what you can do, is extract the element from the container div and placing it somewhere else in the DOM, before fading the container DIV out. That way, It should remain visible.
old question but this would work too
$("#id").click(function() {
$('.swoosh div').not($('.template')).fadeOut('fast');
});
제휴하지 않습니다 StackOverflow