empty()

Removes the contents (child elements and inner HTML) from one or more HTML elements, which can be:

  • The elements that match the selector of a script (see results).
  • One element that matches the selector of a script that runs for "Each matched element" (see this and Setting the scope of a script).
  • The elements returned by a query in the template (see query()).

Use remove() to remove the elements themselves.

Example

This script empties all Span elements found in the template.

Copy
results.empty();

 

Selector Paragraph before script execution Paragraph after script execution
span ​<p>Lorem ipsum <span>dolor sit</span> amet, consectetuer adipiscing elit.</p> ​<p>Lorem ipsum <span></span> amet, consectetuer adipiscing elit.</p>​