Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. var arr = [2,5,8,11,14,17,....];
  2.  
  3. <ul>
  4. <li>testing</li>
  5. <li>testing</li> // -->2nd li be green
  6. <li>testing</li>
  7. <li>testing</li>
  8. <li>testing</li> // -->5th li be green
  9. <li>testing</li>
  10. <li>testing</li>
  11. <li>testing</li> // -->8th li green like this
  12. <li>testing</li>
  13. <li>testing</li>
  14. <li>testing</li>
  15. <li>testing</li>
  16. <li>testing</li>
  17. <li>testing</li>
  18. </ul>
  19.  
  20. ul li:nth-child(2n + 2){
  21.  
  22. color: green;
  23. }
  24.  
  25. arr.forEach(function(num){
  26. $('ul li').eq(num - 1).css('backgroundColor', 'green');
  27. // or $('ul li:nth-child('+ num + ')').css('backgroundColor', 'green');
  28. });
  29.  
  30. li:nth-child(2) {
  31. background: #ff0000;
  32. }
  33.  
  34.  
  35. li:nth-child(3n+0) {
  36. background: #ff0000;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement