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

  • Equal Height

    This plug-in makes HTML-elements equal height by adjusting their min-height CSS properties. Of course IE6 has no clue what min-height means so the plu...

    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

  • Colour Picker

    Use this plug-in on a normal <select>-element filled with colours to turn it in to a colour-picker widget that allows users to view all the colours in...

    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...

Page cached. Loaded in: 0.0093 second(s).
Last DB change: 2012-02-04 08:04:40
Last file change: 2011-10-03 07:42:35
Cache created: 2012-02-04 11:04:39