开发者

add border-bottom to the li by jquery?

<li><a target="_blank" href="#">test one</li>
<li><a target="_blank" href="#">test one</li>
<li><a target="_blank" href="#">test one</li>
<li><a target="_blank" href="#">test one</li>
<li><a target="_blank" href="#">test one</li>
<li><a target="_blank" href="#">test one</li>
<li><a target="_blank" href="#">test one</li>
<li><a target="_blank" href="#">test one</li>
<li><a target="_blank" href="#">test one</li>

I only want to add the border-bottom to the third and sixth line? why the following code doesn't work?

$(li:lt(2,5)).css('border-bottom开发者_如何学编程','1px solid red');


The :lt() pseudo-selector takes one argument only (what is less than 2 is also less than 5!).

$('li:eq(2), li:eq(5)').css('border-bottom','1px solid red');

The above is one way to do it. (demo)

Alternatively, you could introduce a .filter() (demo):

$('li').filter(function(index) {
    return index == 2 || index == 5;
}).css('border-bottom','1px solid red');


You have to close you a tags and enclose selector in quotes. Also change selector a bit.

Final jQuery in my opinion looks like this:

$("li:eq(2), li:eq(5)").css('border-bottom','1px solid red');

Try this fiddle: http://jsfiddle.net/KVpts/


$("li:eq(2),li:eq(5)").css({'border-bottom':'1px solid red'});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜