- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove all child nodes from a parent using jQuery?
To remove all child nodes from a parent, use the empty() method. The empty() method removes all child nodes from the set of matched elements.
Example
You can try to run the following code to learn how to remove all child nodes from a parent −
<html> <head> <title>jQuery empty() method</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $("div").click(function () { $(this).empty(); }); }); </script> <style> .div { margin:10px; padding:12px; border:2px solid #666; width:60px; } </style> </head> <body> <p>Click on any square below to see the result:</p> <div class = "div" style = "background-color:yellow;">ONE</div> <div class = "div" style = "background-color:gray;">TWO</div> </body> </html>
- Related Articles
- How to remove all child nodes from a parent node using jQuery?
- How to remove all child nodes from a parent in jQuery?
- jQuery parent > child Selector
- Program to remove all nodes with only one child from a binary tree in Python?
- How to select ALL children (in any level) from a parent in jQuery?
- How to remove all style attributes using jQuery?
- How to remove all CSS classes using jQuery?
- How to remove all CSS classes using jQuery?
- How to get the child element of a parent using JavaScript?
- How to remove all the elements from DOM using element ID in jQuery?
- How to expand JTree row to display all the nodes and child nodes in Java
- How to remove underline from text hyperlink using jQuery?
- How to remove an element from DOM using jQuery?
- How to insert element as a first child using jQuery?
- How to insert element as a last child using jQuery?

Advertisements