Vanilla JavaScript

Vanilla JavaScript Tabs

Tiny and awesome

Demo

ONE

Shabby chic ennui cred godard, forage roof party scenester health goth typewriter pitchfork. Stumptown whatever fap, austin heirloom asymmetrical lo-fi ethical seitan. Post-ironic hella listicle brunch meggings artisan. YOLO tattooed blue bottle, fanny pack gluten-free put a bird on it migas forage trust fund.

TWO

Shabby chic ennui cred godard, forage roof party scenester health goth typewriter pitchfork. Stumptown whatever fap, austin heirloom asymmetrical lo-fi ethical seitan. Post-ironic hella listicle brunch meggings artisan. YOLO tattooed blue bottle, fanny pack gluten-free put a bird on it migas forage trust fund.

THREE

FOUR

Meggings distillery pop-up artisan, hashtag 90's echo park kickstarter gluten-free. Pinterest gentrify squid vinyl chicharrones meh venmo. Beard aesthetic whatever bicycle rights artisan gastropub. Fingerstache bicycle rights you probably haven't heard of them, schlitz franzen semiotics microdosing.

Shabby chic ennui cred godard, forage roof party scenester health goth typewriter pitchfork. Stumptown whatever fap, austin heirloom asymmetrical lo-fi ethical seitan. Post-ironic hella listicle brunch meggings artisan. YOLO tattooed blue bottle, fanny pack gluten-free put a bird on it migas forage trust fund.

Download

Available on GitHub

Installation

  1. Include the script
    <script src="path/to/vanilla-js-tabs.min.js"></script>
  2. Include the CSS (feel free to edit it or write your own)
    <link rel="stylesheet" href="path/to/vanilla-js-tabs.css">
  3. Write your tabs markup
    <div class="js-tabs" id="tabs">
                            
        <ul class="js-tabs__header">
            <li><a href="#" class="js-tabs__title">Title 1</a></li>
            <li><a href="#" class="js-tabs__title">Title 2</a></li>
            <li><a href="#" class="js-tabs__title">Title 3</a></li>
            <li><a href="#" class="js-tabs__title">Title 4</a></li>
        </ul>
        
        <div class="js-tabs__content">
            <h1>ONE</h1>
        </div>
    
        <div class="js-tabs__content">
            <h1>TWO</h1>
        </div>
    
        <div class="js-tabs__content">
            <h1>THREE</h1>
        </div>
    
        <div class="js-tabs__content">
            <h1>FOUR</h1>
        </div>
        
    </div>
    
  4. Initialize the tabs
    var tabs = new Tabs({
        elem: "tabs",
        open: 2
    });
    
    // Open any other tab
    tabs.open(4);

Options

Option Type Default Description
elem string HTML id of the tab container
open number 0 Starts with this tab oipen

Methods

Method Description
.open(n) Opens a tab by index
.update(n) Updates tabs with n-th tab open
(useful when dynamically adding tabs)
.destroy() Removes the listeners

Licence

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org

Fork me on GitHub