A Simple Color Alternation Script For Lists

Published April 18th, 2006 under JavaScript, Web Development
by Mashhoor Al Dubayan

Here’s an example for a script i’ve made today to set ‘odd’ and ‘even’ class names for each <li> element in a list(s). The source code should be self-explanatory, so i guess no explanation is needed here. :)

7 Responses to “A Simple Color Alternation Script For Lists”

  1. 1 Peach

    Your script doesn’t really seem to work, or if you made a Javascript, you forgot to include the script.

  2. 2 Mashhoor Al Dubayan

    Fixed. Thanks for pointing that out.

    Actually it WAS linked properly, but it seems like Internet Explorer didn’t support the method i’ve used (Firefox and Opera did). It should work now (refresh if it doesn’t).

  3. 3 Vinnie Garcia

    That loop can be cleaned up a little with less code repetition. Here’s how I would do it :)

    for(var i=0; i

  4. 4 Vinnie Garcia

    hmmm….my comment was eaten :(

    Again, all in one line:

    for(var i=0; i

  5. 5 Twig

    It’s the < that’s killing it, Vinnie. :p

  6. 6 Vinnie Garcia

    Yeah I realized that, I just emailed the code instead :)

  7. 7 Mashhoor Al Dubayan

    Thanks Vinnie. I should’ve thought of the ternary operator.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>