Trying to get the accordion open and collapse only when it's being clicked. I am able to open/collapse it but it is getting closed also when another accordion is clicked.
It should open or close on its own - independently from other accordions.
This is what I have tried.
JS:
$(document).on("click", ".accordion-toggle", function () {
if ($(this).attr('class').indexOf('open') == -1)
$(this).toggleClass("open").next().slideToggle('fast');
//Hide the other panels
$(".accordion-toggle").not($(this)).removeClass("open");
$(".accordion-content").not($(this).next()).slideUp('fast');
});
Fiddle:
Demo
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…