Which method can be used to insert an HTML element as the first child of a parent element?
- appendChild()
- insertBefore()
- prepend()
- createElement()
To insert an HTML element as the first child of a parent element, you should use the prepend() method. This method adds the element as the first child, making it the top element within the parent. appendChild() adds it as the last child. insertBefore() requires specifying a reference node. createElement() creates an element but doesn't insert it.
Loading...