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 Slang. A 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');
}
}
});
});
};