下面的代碼允許我切換LI中的div,我如何調整它以便當一個div打開時,兄弟LI內的所有其他div都關閉?切換最接近的div隱藏其他打開的div
$(document).ready(function() {
$('.grey_button a').toggle(function() {
$(this).closest('li').find('.job_description').fadeIn(0);
$(this).toggleClass('open');
//$(this).text($(this).text() == 'More Information' ? 'Hide Information' : 'More Information');
return false;
},
function() {
$(this).closest('li').find('.job_description').fadeOut(0);
$(this).toggleClass('open');
//$(this).text($(this).text() == 'Hide Information' ? 'More Information' : 'Hide Information');
return false;
});
});
HTML
<ul>
<li>
<div class="grey_button"><a href="" class="arrow">More information</a></div>
<div class="job_description" style="display: none; ">
Lorem ipsum
</div>
</li>
<li>
<div class="grey_button"><a href="" class="arrow">More information</a></div>
<div class="job_description" style="display: none; ">
Lorem ipsum
</div>
</li>
<li>
<div class="grey_button"><a href="" class="arrow">More information</a></div>
<div class="job_description" style="display: none; ">
Lorem ipsum
</div>
</li>
</ul>
這很好,除了兄弟姐妹toggleClass沒有改變。直到LI的grey_button a標籤被點擊,「open」類纔會保留。 – JV10
修改了一下...新變量$ list – charlietfl
非常好!現在一切正常!乾杯! – JV10