removeChild( )
Because we’re on the topic of node manipulation, we should take a look at the removeChild( )
method as well.
Using removeChild( )
, we can remove a single node or an entire node tree from the document. This method takes a single argument: the node you want to remove. Suppose we wanted to remove the text node from our div
. We could accomplish that easily using removeChild( )
:
div.removeChild( div.firstChild );
We could even use removeChild( )
to delete the entire body
from the page, which would not be a good thing, but demonstrates its power:
body.parentNode.removeChild( body );
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.