Reputation: 13535
Hi this is my html code :
<ul>
<li>li 1</li>
<li>li 2</li>
<li>li 3</li>
<li>li 4</li>
<li>li 5</li>
</ul>
and this is my jquery code :
$('ul li').each(function(index)
{
if( index > 2 )
{
$(this).css('color','red');
}
});
and this is jsfiddle link : http://jsfiddle.net/YLBcs/
i want to know that exist a other way to do this work without each function ?
Upvotes: 0
Views: 107
Reputation:
SLaks answer quite better. try this one. it's perform faster then SLaks example
$('li:gt(2)','ul').css('color','blue');
Upvotes: 1
Reputation: 887225
You're looking for the :gt
selector:
$('ul li:gt(2)').css('color','red');
Upvotes: 7