JavaScript removeChild() Method Tutorial

In this section, we will learn what the removeChild() method is and how to use it in JavaScript.

What is Element removeChild() Method in JavaScript?

The JavaScript Element removeChild() method is used to remove a child from an HTML element.

Note: after calling this method to remove a child, that child is no-longer part of the DOM. This means users won’t see it anymore.

JavaScript removeChild() Method Syntax:

element.removeChild(child-node);

JavaScript removeChild() Method Parameter

The method takes one argument and that is a reference to the child element we want to remove.

JavaScript removeChild() Method Return Value

The return value of this method is a reference to the child element that was removed from the target element.

Note: if the specified child did not exist in the target element, the value null will return instead.

Example: remove child in JavaScript

See the Pen remove child in JavaScript by Omid Dehghan (@odchan1) on CodePen.

Example: JavaScript remove element by id

See the Pen JavaScript remove element by id by Omid Dehghan (@odchan1) on CodePen.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies