[英]Accordion Open/Close All In Section
I have several basic-accordion-container 's.我有几个基本的手风琴容器。 When I run this, it will expand ONE group of accordions (which it should) but I can not go and expand another group of accordions until I close the opened group.当我运行它时,它将展开一组手风琴(它应该),但我不能 go 并展开另一组手风琴,直到我关闭打开的组。
basicAccordianToggle = function(){
if ($('.expand-all-these').length) {
$('.expand-all-these').on('click', function(e){
e.preventDefault();
if ($('.expand-all-these').hasClass('collapsed')) {
$(this).parents('.basic-accordion-container').find('.collapse').collapse('hide');
$(this).parents('.basic-accordion-container').find('.expand-all-these').html('Expand All <span class="plus">+</span>');
$(this).parents('.basic-accordion-container').find('.expand-all-these').removeClass('collapsed');
}else{
$(this).parents('.basic-accordion-container').find('.collapse').collapse('show');
$(this).parents('.basic-accordion-container').find('.expand-all-these').html('Collapse All <span class="plus">-</span>');
$(this).parents('.basic-accordion-container').find('.expand-all-these').addClass('collapsed');
}
})
}
} }
You have to check hasClass
for the clicked element instead of all elements, so use this
to refer clicked element.您必须检查hasClass
是否为单击的元素而不是所有元素,因此使用this
来引用单击的元素。
basicAccordianToggle = function(){
if ($('.expand-all-these').length) {
$('.expand-all-these').on('click', function(e){
e.preventDefault();
if ($(this).hasClass('collapsed')) {
// ---^^^^-------- here
$(this).parents('.basic-accordion-container').find('.collapse').collapse('hide');
$(this).parents('.basic-accordion-container').find('.expand-all-these').html('Expand All <span class="plus">+</span>');
$(this).parents('.basic-accordion-container').find('.expand-all-these').removeClass('collapsed');
}else{
$(this).parents('.basic-accordion-container').find('.collapse').collapse('show');
$(this).parents('.basic-accordion-container').find('.expand-all-these').html('Collapse All <span class="plus">-</span>');
$(this).parents('.basic-accordion-container').find('.expand-all-these').addClass('collapsed');
}
})
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.