Numeric 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

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

How to Use

jQuery('#glossary dl').numericDL();

Example

Jug
A small pitcher.
Vulgar Slang. A woman's breasts.
Bird
The animal of the skies

Example Code

HTML

<div id="jquery-numeric-dl-example">
<
dl>
    <
dt>Jug</dt>
    <
dd>A small pitcher.</dd>
    <
dd>Vulgar SlangA woman's breasts.</dd>
    <dt>Bird</dt>
    <dd>The animal of the skies</dd>
</dl>
</div>

JS

jQuery('#jquery-numeric-dl-example dl').numericDL();

Source Code

jQuery.fn.numericDL = function () {
    return 
this.each(function () {
        
jQuery('dt'this).each(function () {
            var 
numDDs    0;
            var 
dt        jQuery(this);
            var 
dd        dt.next('dd');
            var 
i        1;

            while (
dd.length) {
                
dd dd.next('dd');
                
numDDs++;
            }

            if (
numDDs 1) {
                
dd dt.next('dd');

                while (
dd.length) {
                    
dd.text('(' i++ + ') ' dd.text());
                    
dd dd.next('dd');
                }
            }
        });
    });
};

Download

Plug-in

Requires

Random jQuery Plug-ins

  • Live Validation

    Use this plug-in to add live validation to any form on your page. The plug-in indicates whether a form control is valid or not by switching between an...

    Details

  • Show Password

    This little plug inserts a "View password"-checkbox next to inputs of type password that allows the user to toggle the password's visibility. When the...

    Details

  • 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

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