The Accordion constructor creates a new accordion instance.
Signature: new Accordion(container, options)
Parameters:
container (required): A selector string, a DOM element, or an array of selector strings or HTMLElements that specify the accordion container(s).options (optional): A configuration object to customize behavior.
// Initialize with custom options
new Accordion(".container-second", {
duration: 400,
showMultiple: true,
onOpen: function (currentElement) {
console.log(currentElement);
}
});
// Initialize multiple containers at once using an array of selectors
new Accordion([".container-first", ".container-second"], {});
// Initialize using an array of HTMLElements
const accordions = Array.from(document.querySelectorAll(".accordion-container"));
new Accordion(accordions, {});