//Accordion START //$(".js-accordion-item:nth-child(1)").addClass("active"); // define the accordion function let accordion = (function () { // get the accordion class let $accordion = $(".js-accordion"); // get the accordion header class let $accordion_header = $accordion.find(".js-accordion-header"); // get the accordion item class let $accordion_item = $(".js-accordion-item"); // define default settings let settings = { // animation speed speed: 300, // close all other accordion items if true oneOpen: true }; // set the accordion function return return { // pass configurable object literal init: function ($settings) { // the init function // on accordion header click $accordion_header.on("click", function () { // toggle accordion accordion.toggle($(this)); }); // update default settings with the initialization defined settings $.extend(settings, $settings); // ensure only one accordion is active if oneOpen is true // if one accordion is open & accordions with the class active are more than one if (settings.oneOpen && $(".js-accordion-item.active").length > 1) { // remove the active class from all other accordion items except the first $(".js-accordion-item.active:not(:first)").removeClass("active"); } // reveal the active accordion bodies $(".js-accordion-item.active").find("> .js-accordion-body").show(); }, toggle: function ($this) { // the toggle function // if one accordion is open & it's not the first active accordion if ( settings.oneOpen && $this[0] != $this .closest(".js-accordion") .find("> .js-accordion-item.active > .js-accordion-header")[0] ) { // remove the active class & close it $this .closest(".js-accordion") .find("> .js-accordion-item") .removeClass("active") .find(".js-accordion-body") .slideUp(); } // show/hide the clicked accordion item by adding/removing active class & toggling slideUp/slideDown $this.closest(".js-accordion-item").toggleClass("active"); $this.next().stop().slideToggle(settings.speed); } }; })(); // when the DOM is ready $(document).ready(function () { // initialize the accordion its respective settings accordion.init({ speed: 300, oneOpen: true }); }); // Accordion OVER