Search code examples
dojodestroy

how can i delete a div that i created with dojo?


i create a div with heading and UL inside with dojo.create. how can i totaly delete this div with heading and UL children so that i can create a div with this id again (with different content)?

I create the div like this (i delete some attributes and the h1 and ul creation because it was too much code, i do it the same way like i create the div):

var newAlarmDiv = new dojox.mobile.ScrollableView({
                    id: "divAlarms",
                    dojoType: "dojox.mobile.ScrollableView",
});
newAlarmDiv.placeAt('mobileView','first');

i already tried it with the dojo.destroy command but when i create a new div after destroying it i get many different errors so it seems not to be deleted correctly.

How do i correctly "undo" the div creation?

greets Tom


Solution

  • You are creating a "Widget", which has DOM elements associated with it. If you were destroying only dom elements you would use dojo.destroy.

    Since you want to destroy the widget, you should use destroy or destroyRecursive. The API Docs have a good overview of what each method does.

    var scrollableViewWidget = new dojox.mobile.ScrollableView({/*params*/});
    scrollableViewWidget.placeAt('someDiv','first');
    scrollableViewWidget.destroyRecursive();