Togglable DL 2.0

Created Sunday 31st of August 2008 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

Use this plug-in on your definition-lists (dl-elements) to allow the dd:s for a dt to be toggled when clicking the dt. Don't use it unless it's semantically a definition list of some kind though :)

How to Use

jQuery('#faq dl').togglableDL(); would make every dl in #faq 'togglable'.

Example

Who are you?
Me
Where do you live?
Here

Example Code

HTML

<div id="jquery-togglable-dl-example">
<
dl>
    <
dt>Who are you?</dt>
    <
dd>Me</dd>
    <
dt>Where do you live?</dt>
    <
dd>Here</dd>
</
dl>
</
div>

JS

jQuery('#jquery-togglable-dl-example dl').togglableDL();

Source Code

jQuery.fn.togglableDL = function (conf) {
    var 
config jQuery.extend({
        
speed:     100
    
}, conf);

    return 
this.each(function () {
        var 
dds jQuery('dd'this).slideUp(config.speed);

        
jQuery('dt'this).each(function () {
            var 
dt jQuery(this);

            
dt.html('<a href="#">' dt.html() + '</a>').find('a').toggle(function () {
                var 
isDT false;

                
dt.nextAll().each(function () {
                    if (
isDT || jQuery(this).is('dt')) {
                        
isDT true;
                        return;
                    }

                    
jQuery(this).slideDown(config.speed);
                });
            }, 
            function () {
                var 
isDT false;

                
dt.nextAll().each(function () {
                    if (
isDT || jQuery(this).is('dt')) {
                        
isDT true;
                        return;
                    }

                    
jQuery(this).slideUp(config.speed);
                });
            });
        });
    });
};

Download

Plug-in

Requires

Random jQuery Plug-ins

  • Ajax Loader

    Use this plug-in when you want to inform your visitors that a certain part of your page is currently loading. The plug-in adds a faded 'loading-div' o...

    Details

  • Center

    This little pluggy centers an element on the screen using either fixed or absolute positioning. Can be used to display messages, pop up images etc.

    Details

  • Togglable DL

    Use this plug-in on your definition-lists (dl-elements) to allow the dd:s for a dt to be toggled when clicking the dt. Don't use it unless it's semant...

    Details

More Plug-ins

Recent Comments

  1. AL on "Accessible, Stylish Modal Windows With Modern CSS"

    @Matt - What exactly isn't working? "Not working" ...

  2. roboteich on "Accessible, Stylish Modal Windows With Modern CSS"

    This is hardly accessible. Screen reader focus is...

  3. Matt on "Accessible, Stylish Modal Windows With Modern CSS"

    I have tried to implement this, but for some reaso...

Page cached. Loaded in: 0.0087 second(s).
Last DB change: 2010-09-03 17:14:49
Last file change: 2010-08-12 15:31:16
Cache created: 2010-09-08 04:29:19