Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
How to remove all child nodes from a parent in jQuery?
To remove all child nodes from a parent in jQuery, use the empty() method.
Example
The jQuery empty() method removes all child nodes of the set of matched elements from the DOM.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function() {
$("#demo").empty();
});
});
</script>
</head>
<body>
<ul id='demo'>
<li>India</li>
<li>US</li>
<li>UK</li>
</ul>
<button>Remove all child nodes</button>
</body>
</html>Advertisements