The jQuery empty function removes all the internal content including HTML elements of the selected element. It does not remove the selected element but removes content inside the selected element.

See the example given below.
Example of jQuery empty

Output


Welcome to Tutorialdeep Web Tutorial.

Learn jQuery With Working Examples.

The example given above contains the button and the div element which you have to make empty using the jQuery empty method. When you click the ‘Click me’ button given above, the script makes the div element empty by removing all the child content of the selected element.

Syntax of jQuery empty()

Sr. No Parameter Name Description
1 selector Specify the element you want to select and make it empty by removing the child elements. It is the required field.

jQuery Empty Multiple Elements on Click

If you want to empty multiple element of same HTML tag type, you can do so by adding click event on all the div’s. Here, see below example to find out how you can perform this task.

Example 1

Output

Click below colored div’s to make them empty.

Tutorialdeep is a Web Development and Blogging Tutorial.

Learn Web Development Here.
Learn jQuery With Working Examples.

The above example makes all the clicked div’s empty. The script uses the class name of the div to select the element and apply the jQuery empty method.

You must also learn:-

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.