以下代码允许我切换 LI 内的 div,我如何调整它以便当一个 div 打开时,兄弟 LI 内的所有其他 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>