#1
  1. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,042
    Rep Power
    535

    Target last element of a list


    Hi, How can I target the last element of a list. The number of items in the list is not always four. Thanks
    Code:
    <div id="mainmenu">
    <div class="mod_menu">    
    <ul>
    <li>first</li>
    <li>second</li>
    <li>third</li>
    <li>last</li>
    </ul>    
    </div>
    </div>
  2. #2
  3. Person
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2007
    Location
    Moon
    Posts
    1,158
    Rep Power
    550
    You can put the list items in an array and loop through, writing a conditional for the last item in it, (with a server side scripting language). That's the way I recommend.

    There's also the last-child pseudo selector for browsers that support css3.
    Give Opera some love. Use it and you'll see why.

    Oh, those monkeys.::What's wrong with the world today?::The lion king in 5 seconds.

    My body is so sexy.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,042
    Rep Power
    535
    I was thinking about last-child, but didn't want to use it.

    I first thought that your server side solution wouldn't work since I also need a selected class, but then recalled that more than one class can be applied to an element.

    Thanks!

IMN logo majestic logo threadwatch logo seochat tools logo