tags:

views:

31

answers:

2

I'm trying to select the first list item li in the ul#suckerfishnav in the main navigation here: http://fluroltd.com/clients/harveys/. Using

$('ul#suckerfishnav').find('li').slice(0,1) {
    $(this).css('background-color', 'red');
});

My aim is to add a class="first" to the first li in the list.

+3  A: 

Try this:

$('ul#suckerfishnav li:first-child').addClass("first");

I've updated your jsFiddle to show it working

ILMV
Thank you it worked.
Solidariti
Glad I could help John, mark this answer as accepted if your problem has been solved :-)
ILMV
A: 

You could just use plain CSS for this too:

#suckerfishnav li:first-child {background-color:Red;);
assuming it's supported in the browsers of choice
jamiebarrow
If you look back at his question he want's to add the class of `first`, I guess he's using bg=red just to show the selector working. Also first-child is not support by all browsers, especially older ones.
ILMV
who uses these 'older' browsers anyway, they should be shot!:)Okay, fair point, I was just suggesting CSS may (or may not) be an easier way to do it.