📅  最后修改于: 2022-03-11 15:02:34.040000             🧑  作者: Mango
//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