CSS Odd ровный ребенок
tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}
Alive Albatross
tr:nth-child(even) {background: #CCC}
tr:nth-child(odd) {background: #FFF}
/* Selects the second <li> element in a list */
li:nth-child(2) {
color: lime;
}
/* Selects every fourth element
among any group of siblings */
:nth-child(4n) {
color: lime;
}
//method one
var c = document.getElementById("myDIV").childNodes;
c[1].style.backgroundColor = "yellow";//first child
c[2].style.backgroundColor = "red";//second child
c[-1].style.backgroundColor = "green";//last child
c[-2].style.backgroundColor = "blue";//secound last child
//method two
let nth-child = document.querySeletorAll('myDiv:nth-child(n)');//gives nth child
:nth-child(1) { /*advantage is you can do it for 2nd, 3rd etc. */
/* styles go here*/
}
//you can use the css nth-child property like this:
var second-child = document.querySeletorAll('[your element name]:nth-child(2)');
2
3
4
5
6
7
8
9
0
0
0