Return to Snippet

Revision: 28453
at July 8, 2010 17:29 by omerta83


Initial Code
/*
<ul>  
<li>Apples</li>  
<li>Pears</li>  
<li>Cherries</li>  
<li>Grapes</li>  
<li>Mangos</li>  
</ul>
*/

/*If we just want to set the background-color of 
  everything after element number two (pears) we 
  can do this using:*/  
  
$('li').slice(2).css('background-color', 'yellow');  
  
/*and if we want to set the bg-color of the elements 
  after two(pears), but only up to and including 4 
  (grapes), we can use:*/  
  $('li').slice(2, 4).css('background-color', 'green')

Initial URL


Initial Description


Initial Title
Using .slice() method to style only particular elements within a list

Initial Tags
javascript, jquery

Initial Language
JavaScript