How to use jQuery empty() Method with setTimeout()

In this demo, I am using two popular jQuery methods called empty() and setTimeOut(). The idea is to clear the contents of an element or multiple elements after a delay.

🚀 I have 3 different elements inside a DIV element. I wish to clear all the contents inside the DIV after a delay of 5 seconds. The setTimeOut() method will create a delay of 5000 miliseconds before calling the jQuery empty() method to clear all the contents.

This sentence is inside a <div> element

This is inside <p> element

This is inside a <span> element

You can clear or empty a DIV element using plain old JavaScript 🚀. Check this out.

Do you know the difference between .empty() and .remove() methods in jQuery? If no, then read this tutorial.

Go back to the Tutorial
More interesting and interactive Demos