

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove the child node of a specific element in JavaScript?
To remove the child node of a list javascript has provided removeChild() method. Using this method we can remove any list item using its index position. Let's discuss it in a nutshell.
syntax
node.removeChild(node);
Example-1
In the following example, there are 3 elements in the provided list but after removing a child there are only two elements in the list and they were displayed in the output.
<html> <body> <ul id = "list"><li>Tesla</li><li>Spacex</li><li>Solarcity</li></ul> <script> var list = document.getElementById("list"); list.removeChild(list.childNodes[1]); </script> </body> </html>
Output
Tesla Solarcity
Example-2
In the following example, there are 3 elements in the provided list but after removing the first child using method removeChild() the other remaining two elements left were displayed as shown in the output.
<html> <body> <ul id = "list"><li>Tesla</li><li>Spacex</li><li>Solarcity</li></ul> <script> var list = document.getElementById("list"); list.removeChild(list.childNodes[0]); </script> </body> </html>
Output
Spacex Solarcity
- Related Questions & Answers
- First and last child node of a specific node in JavaScript?
- Remove all child elements of a DOM node in JavaScript?
- How can I remove a child node in HTML using JavaScript?
- How can I remove all child elements of a DOM node in JavaScript?
- Child node count in JavaScript?
- Replace a child node with a new node in JavaScript?
- Insert a node as a child before an existing child in JavaScript?
- How to remove all child nodes from a parent node using jQuery?
- How to get the child element of a parent using JavaScript?
- Remove a specific element from a LinkedList in Java
- Java Program to count the child of root node in a JTree
- Value of the class attribute node of an element in JavaScript?
- Python Program to remove a specific digit from every element of the list
- How to remove Specific Element from a Swift Array?
- Node name of an HTML element using javascript?
Advertisements