There were a few things in your accordion code that I installed below.
- When you click on the arrow, the accordion should expand only the current list and not all, this can be done by contacting the current parents of the elements, and then extracting the descendant element
.community-sub-row . - The Accordion list was not collapsed at loading, instead it happened on
document.ready() , which was not very good, so I added CSS style to hide the list by default. - when he clicked on the accordion, he had to first collapse all existing accordions before expanding the current one.
JS CODE:
$(document).ready(function() { $(".community-toggle-arrow").click(function() { //collapse all accordion before toggling except current $('.community-sub-row').not(this).slideUp(); $(this).closest('.community-row').find(".community-sub-row").slideToggle(); $(this).find("span").toggleClass("ion-arrow-right-b"); }); });
CSS
.community-row .community-sub-row { padding: 0 0 0 17px; display:none; //to hide all accordion on load }
Live Demo @JSFiddle
source share