Learn how Scrivito CMS can help you deliver amazing digital experiences
See Scrivito CMS in action


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.


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.