开发者

jQuery select list element not working

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.


Try this:

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

I've updated your jsFiddle to show it working


You could just use plain CSS for this too:

#suckerfishnav li:first-child {background-color:Red;);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜