Return to Snippet

Revision: 22439
at January 12, 2010 15:20 by smoothdzion


Initial Code
$(function(){
  $("li:first-child").addClass("first_item");
  $("li:last-child").addClass("last_item");
});

Initial URL

                                

Initial Description
Since :first-child and :last-child aren't compatible with all modern browsers I thought I'd post this snippet.  It make automating the class creation easier too instead of having to remember when typing up your HTML or creating logic in your programming.

Rename "first-item" and/or "last-item" to whatever class you want to use.  You can change the "li" part of the code to whatever element your want or even remove it altogether.

Initial Title
jQuery - Add First and Last Class to LI

Initial Tags
css, jquery

Initial Language
jQuery