cferdinandi / tabby

Lightweight, accessible vanilla JS toggle tabs.
MIT License
598 stars 73 forks source link

Allow passing a node instead of a selector #134

Open JacobDB opened 2 years ago

JacobDB commented 2 years ago

I've come across some situations where I don't know how many sets of tab will be on a page, and so have to loop over all instances of [data-tabs] to initialize a Tabby for it. I've achieved this with..

const ELEMENTS = document.querySelectorAll("[data-tabs]");

if (ELEMENTS.length > 0) {
    ELEMENTS.forEach((element) => {
        new Tabby(`#${element.getAttribute("id")}`);
    });
}

but that seems somewhat fragile and also confusing to read. Being able to directly pass element in this case would really simplify things.