Togglable DL 2.0

Created Sunday 31st of August 2008 by Andreas Lagerkvist
Copyright © 2008 Andreas Lagerkvist (andreaslagerkvist.com)

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

blog comments powered by Disqus

Random jQuery Plug-ins

  • Max Length Form Controls

    Gives form-controls with a 'maxlength-XXX'-class a max-length and prohibits user from entering more than set amount. It also displays number of charac...

    Details

  • Slide Presentation

    A sort of slide/presentation kind of plug-in. Displays sliding images with text floating on top. This one's pretty specific but perhaps someone will f...

    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

More Plug-ins

Recent Comments

Powered by Disqus
Page cached. Loaded in: 0.0245 second(s).
Last DB change: 2012-04-02 11:06:05
Last file change: 2012-04-25 20:30:39
Cache created: 2012-05-18 01:52:59