js firstchild code example
Example 1: css first child
:first-child {
}
:nth-child(1) {
}
Example 2: first child element javascript
Both these will give you the first child node:
console.log(parentElement.firstChild);
console.log(parentElement.childNodes[0]);
If you need the first child that is an element node then use:
console.log(parentElement.children[0]);
Example 3: javascript take first element of array
const array = [1,2,3,4,5];
const firstElement = array.shift();
Example 4: how to add first child using js
var eElement;
var newFirstElement;
eElement.insertBefore(newFirstElement, eElement.firstChild);