replaceChild( )
Let’s suppose that instead of inserting our new div
before the firstChild
of the body
element, we wanted it to replace the firstChild
.
To do so, we could use the replaceChild( )
method:
body.replaceChild( new_div, body.firstChild );
Like insertBefore( )
, replaceChild( )
takes two arguments: The first argument is the node you want inserted in the place of the node that is the second argument.
Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.