1var li = document.querySelector("li");
2var number = 13;
3li.children[0].children[0].innerHTML = number;
1
2
3
4
5 let content = document.getElementById('menu');
6let firstChild = content.firstChild.nodeName;
7console.log(firstChild);Code language: JavaScript (javascript)
1
2
3
4
5 let firstChild = parentElement.firstChild;
6Code language: JavaScript (javascript)
1Syntax
2element.children
3
4Example
5Change the background color of the second child element of a <div> element:
6
7var c = document.getElementById("myDIV").children;
8c[1].style.backgroundColor = "yellow";
1
2
3
4
5 let lastChild = parentElement.lastElementChild;Code language: JavaScript (javascript)