Numeric DL 2.0

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

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

Post a Comment

blog comments powered by Disqus

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

  • 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

  • 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

More Plug-ins

Recent Comments

Powered by Disqus