How to use jQuery .slice() to reduce the set of matched HTML elements to a subset specified by a range of numbers

2 Answers

0 votes
<!doctype html>
<html>
<head>
  <script src="js/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>

<ul>
  <li>list item 1</li>
  <li>list item 2</li>
  <li>list item 3</li>
  <li>list item 4</li>
  <li>list item 5</li>
</ul>
<script>
$( "li" ).slice(3).css( "background-color", "purple" );
</script>
</body>
</html>

 



answered Aug 22, 2016 by avibootz
0 votes
<!doctype html>
<html>
<head>
  <script src="js/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>

<ul>
  <li>list item 1</li>
  <li>list item 2</li>
  <li>list item 3</li>
  <li>list item 4</li>
  <li>list item 5</li>
</ul>
<script>
$( "li" ).slice(1, 4).css( "background-color", "purple" );
</script>
</body>
</html>

 



answered Aug 22, 2016 by avibootz
...