Scrivito is proudly made by JustRelate Group in Berlin, Germany, and Wrocław, Poland.
Scrivito is proudly made by JustRelate Group

destroy()

Deletes the widget.

Widgets that aren’t needed anymore (because they have been superseded by a new version, for example), can be easily removed from a page by calling destroy() on them.

After deleting a widget using widget.destroy(), it can no longer be accessed. The result of a function call on a destroyed widget is not defined.

Examples

Directly delete a single widget:

page = Scrivito.currentPage();
page.get("body");
// => [widget1, widget2]
widget = page.get("body")[0];
widget.destroy();
page.get("body");
// => [widget2]

Delete specific widgets from a page:

page = Scrivito.currentPage();
page.widgets()
  .filter(w => {
    return w.objClass() == "UnwantedWidget";
  })
  .forEach(unwantedWidget => {
    unwantedWidget.destroy();
  });

See Performing Bulk Operations for further usage examples.