开发者

jQuery select list element not working

开发者 https://www.devze.com 2023-01-12 21:44 出处:网络
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

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

精彩评论

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