We use the parentElement
property of a Node object to get the parent element of a DOM element. Similarly, we utilize the children
property of the Element object to get all the children of a DOM element as a live HTMLCollection.
div
element with the parent
ID. Inside this element, we have another div
element with a first_child
ID. Inside the first_child
div
element, we add two span elements.firstChild
and assign the div
element with the first_child
ID as a value. parentElement
property of the firstChild
object.parentElement
using the outerHTML
property.children
property of the firstChild
object and store it in the variable named children
. children
variable and print the HTML content of all child elements.