1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Can you make an ordered list count down instead of up?

Discussion in 'HTML & Website Design' started by lorien1973, Apr 13, 2007.

  1. #1
    Or, can you set the value for each <li> so you can make a top ten list (which should go from 10 -> 1 instead of 1 -> 10) ?
     
    lorien1973, Apr 13, 2007 IP
    Will.Spencer likes this.
  2. depi

    depi Active Member

    Messages:
    845
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    68
    #2
    depi, Apr 13, 2007 IP
  3. lorien1973

    lorien1973 Notable Member

    Messages:
    12,206
    Likes Received:
    601
    Best Answers:
    0
    Trophy Points:
    260
    #3
    Thanks I just found this and it works rather well:

    <ol id="reverse_numbering">
    <li>foo</li>
    <li>bar</li>
    <li>baz</li>
    </ol>
    <script type="text/javascript">
    var reverse=document.getElementById('reverse_numbering');
    reverse.style.listStyle='none';
    var li=reverse.getElementsByTagName('li');
    for(var i=0; i<li.length; i++)
    {
    li.insertBefore(document.createTextNode(li.length-i+'. '), li.firstChild);
    }
    </script>

    The only problem with this code is that if you have lists embedded with a smaller list, it counts incorrectly, so placement of the javascript (after the last <li> is important).

    Here it is in action :)

    http://www.mediaflyboy.com/top-10-zombie-movies

    Pretty simple and effective!
     
    lorien1973, Apr 13, 2007 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    What you ask is covered by a simple css property set, generated content and automatic numbering. All modern browsers have support. Trouble is, IE is not a modern browser. You could put the javascript in a conditional comment, feeding it to IE only. If the javascript is disabled, only IE users will feel the pinch.

    cheers,

    gary
     
    kk5st, Apr 13, 2007 IP
  5. the_pm

    the_pm Peon

    Messages:
    332
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #5
    A little negative text-indent might make this look a little more like a proper ordered list ;)

    Nice piece of code!
     
    the_pm, Apr 13, 2007 IP