Skip to content Skip to sidebar Skip to footer

Marking Up Ordered Definition List

I'm looking for the most semantically correct and sane method of marking up an ordered definition list. I have thought about hte following ways of doing it. First I used an ordered

Solution 1:

However as I need to be able to access each definition programmatically through Javascript I'm not sure that this would work.

Just get each definition term <dt> and then get the element next to it in the DOM tree, which should always be the definition description <dd>. jQuery is of great help in here. Here's an SSCCE, just copy'n'paste'n'run it:

<!doctype html><htmllang="en"><head><title>SO question 2172138</title><scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script><script>
            $(document).ready(function() {
                $('#dl dt').each(function(i, dt) {
                    dt = $(dt);
                    dds = dt.nextAll().map(function() { return $(this).is('dd') ? this : false; });
                    alert(dt.text() + " = " + dds.text());
                });
            });
        </script></head><body><dlid="dl"><dt>Term1</dt><dd>Desc1a</dd><dd>Desc1b</dd><dt>Term2</dt><dd>Desc2a</dd><dt>Term3</dt><dd>Desc3a</dd><dd>Desc3b</dd></dl></body></html>

Solution 2:

Use names and IDs.

<dl id="1">

Document.getElementById("1");

https://developer.mozilla.org/En/DOM/Document.getElementById

Post a Comment for "Marking Up Ordered Definition List"