removeElement( )


Removes a widget element from the stage.

The removeElement() function returns a Promise that is resolved when the element is removed. You can only remove elements that are part of the widget with which the panel is associated.
The element selector is a string with the hash symbol (#) followed by the ID of the item you want to select (for example, "#myElement"). To use this function on an inner (nested) widget, use getScopedWixEditor().

Method Declaration
Copy
function removeElement(selector: string): Promise<void>;
Method Parameters
selectorstringRequired

An element selector.

Use a toggle switch to remove/restore a widget element
JavaScript
// In this example, we use a toggle switch to remove or restore an element in our widget. import wixEditor from "wix-editor"; $w.onReady(async function () { $w("#toggleSwitch").onClick(async (event) => { if (event.target.value) { await wixEditor.removeElement("#title"); } else { await wixEditor.restoreElement("#title"); } }); });
Errors

This method doesn’t return any custom errors, but may return standard errors. Learn more about standard Wix errors.

Did this help?