What is the empty() method in jQuery?

In jQuery, the empty() method is used to remove all the child elements of the selected element in the jQuery collection.

Syntax


(a).empty()

  • a is the element from which we will remove all child elements.

Code

In the code below, the content of the span elements are all removed once the Remove button is clicked.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources