---
title: "Why are use the empty method in JQuery?"  
description: "Why are use the empty method in JQuery?"  
author: "Ethan Karla"  
published: 2021-07-28  
canonical: https://answers.mindstick.com/qa/93809/why-are-use-the-empty-method-in-jquery  
category: "web application"  
tags: ["web development", "web application development"]  
reading_time: 3 minutes  

---

# Why are use the empty method in JQuery?

Why are use the empty [method in JQuery](https://www.mindstick.com/forum/156670/has-method-in-jquery)?

## Answers

### Answer by Ravi Vishwakarma

The jQuery empty() [method](https://www.mindstick.com/articles/23411/the-most-effective-method-to-find-the-perfect-small-business-phone-system-for-your-business) is used to remove content and child nodes from selected elements. This method does not remove by itself.

> Syntax\
> $(selector).empty()

```
<!DOCTYPE html>
<html>
<head>
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
    <script>
        $(document).ready(function () {
            $('.remove').click(function () {
                $('.main').empty(); // empty method
            });
            $('.add').click(function () {
                $('.main').text('Lorem ipsum dolor sit amet,'
                    + 'consectetur adipiscing elit, sed do eiusmod tempor'
                    + ' incididunt ut labore et dolore magna aliqua.'
                    +'Ut enim ad minim veniam,'
                    +'quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ');
            });
        });
    </script>
    <style>
        body {
            padding:10px;
            margin:10px;
            box-sizing:border-box;
        }
         div{
            background-color:orange;
            color:white;
            width:50%;
            height:auto;
            font-size:35px;
            padding:10px;
            margin:10px;
            border:2px solid black;
        }
    </style>
</head>
<body>
    <button class='remove'>Empty Data form box</button>
    <button class='add'>add Data in box</button>
    <div class='main'>
    Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        Lorem Ipsum has en the industry's standard dummy text ever since the 1500s,
         when an unknown printer took a galley of type and scrambled it to make a type
         specimen book. It has survived not only five centuries, but also the leap into                 electronic typesetting, remaining essentially unchanged.
    </div>
</body>
</html>
```

Output: ![Why are use the empty method in JQuery?](https://answers.mindstick.com/questionanswer/42b97ac4-7b4c-4002-bdd8-083bc26bcc03/images/e861e282-533a-4589-b465-4e5079b7be51.png) \


---

Original Source: https://answers.mindstick.com/qa/93809/why-are-use-the-empty-method-in-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
