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 node using jQuery?
Use the jQuery empty() method to remove all child nodes from a parent node.
Example
You can try to run the following code to remove all child nodes from a parent node using jQuery:
<!DOCTYPE html>
<html>
<head>
<style>
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#button1").click(function(){
$("ul").empty();
});
});
</script>
</head>
<body>
<div>
<ul>
<li>li (child)</li>
<li>li (child)</li>
<li>li (child)</li>
<li>li (child)</li>
</ul>
</div>
<button id="button1">Remove</button>
<p>Click Remove to remove all child nodes.</p>
</body>
</html>Advertisements