Super Simple Tabs 1.3

Created Thursday 17th of September 2009 by Andreas Lagerkvist
Copyright © 2008 Andreas Lagerkvist (andreaslagerkvist.com)

Please have a look at the "Other Resources" for bug reports or further help on jQuery. Do not post bug reports or feature requests as comments to unrelated articles. If bug reporting on bugtracker.a-framework.org fails, e-mail me.

What it Does

This is an extremely basic tabs-plugin which allows you to create tabbed content from the ever-so-common list of in-page-links. You can set the selected tab, the show and hide animation as well as the duration through the config argument.

How to Use

jQuery('ul.tabs').superSimpleTabs(); would make every ul with the class 'tabs' hide show the content its links are pointing to.

Example

Content 1
Content 2
Content 3

Example Code

HTML

<div id="jquery-super-simple-tabs-example">
<
ul>
    <
li><a href="#jquery-super-simple-tabs-example-1">Content 1</a></li>
    <
li><a href="#jquery-super-simple-tabs-example-2">Content 2</a></li>
    <
li><a href="#jquery-super-simple-tabs-example-3">Content 3</a></li>
</
ul>
<
div id="jquery-super-simple-tabs-example-1">
    
Content 1
</div>
<
div id="jquery-super-simple-tabs-example-2">
    
Content 2
</div>
<
div id="jquery-super-simple-tabs-example-3">
    
Content 3
</div>
</
div>

JS

jQuery('#jquery-super-simple-tabs-example ul').superSimpleTabs();

Source Code

jQuery.fn.superSimpleTabs = function (conf) {
    var 
config jQuery.extend({
        
selected1
        
show'show'
        
hide'hide'
        
duration0
    
}, conf);

    return 
this.each(function () {
        var 
ul    jQuery(this);
        var 
ipl    'a[href^="#"]';

        
// Go through all the in-page links in the ul
        // and hide all but the selected's contents
        
ul.find(ipl).each(function (i) {
            var 
link jQuery(this);

            if ((
1) === config.selected) {
                
link.addClass('selected');
            }
            else {
                
jQuery(link.attr('href')).hide();
            }
        });

        
// When clicking the UL (or anything within)
        
ul.click(function (e) {
            var 
clicked    jQuery(e.target);
            var 
link    false;

            if (
clicked.is(ipl)) {
                
link clicked;
            }
            else {
                var 
parent clicked.parents(ipl);

                if (
parent.length) {
                    
link parent;
                }
            }

            if (
link) {
                var 
selected ul.find('a.selected');

                if (
selected.length) {
                    
jQuery(selected.removeClass('selected').attr('href'))[config.hide](config.duration, function () {
                        
jQuery(link.attr('href'))[config.show](config.duration);
                    });

                    
link.addClass('selected');
                }
                else {
                    
jQuery(link.addClass('selected').attr('href'))[config.show](config.duration);
                }

                return 
false;
            }
        });
    });
};

Download

Plug-in

Requires

Random jQuery Plug-ins

  • Vibrate

    This plug-in makes any element you want "vibrate" every now and then. Can be used in conjunction with blink for maximum annoyance!

    Details

  • Super Simple Tabs

    This is an extremely basic tabs-plugin which allows you to create tabbed content from the ever-so-common list of in-page-links. You can set the select...

    Details

  • Numeric DL

    This tiny plug-in numbers definitions in a definition-list if there are more than one definition for a term. Can be useful for FAQs, actual lists of d...

    Details

More Plug-ins

Recent Comments

  1. Andreas on "SleekPHP User Handling"

    Thank you for showing interest :) Were the docs en...

  2. ciptard on "SleekPHP User Handling"

    Ok, thank you

  3. Andreas on "SleekPHP User Handling"

    I might write a "getting started" article for Slee...