Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var arr = [2,5,8,11,14,17,....];
- <ul>
- <li>testing</li>
- <li>testing</li> // -->2nd li be green
- <li>testing</li>
- <li>testing</li>
- <li>testing</li> // -->5th li be green
- <li>testing</li>
- <li>testing</li>
- <li>testing</li> // -->8th li green like this
- <li>testing</li>
- <li>testing</li>
- <li>testing</li>
- <li>testing</li>
- <li>testing</li>
- <li>testing</li>
- </ul>
- ul li:nth-child(2n + 2){
- color: green;
- }
- arr.forEach(function(num){
- $('ul li').eq(num - 1).css('backgroundColor', 'green');
- // or $('ul li:nth-child('+ num + ')').css('backgroundColor', 'green');
- });
- li:nth-child(2) {
- background: #ff0000;
- }
- li:nth-child(3n+0) {
- background: #ff0000;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement