Login Register

Identify/destroy widgets that are descendents of a DOM Node

The environment into which I'm integrating Dojo's widgets requires me to be able to locate any Dojo widgets that have been created as descendents of a specified DOM node (by Id), so that I can destroy these before the innerHTML of the specified DOM node is replaced by another fragment (which may potentially bring in more widgets).

At present this isn't as easy as it seems, because some widgets get parsed into DOM nodes that are positioned into the DOM outside their original logical node hierarchy (ie as represented by their original "raw" widget tags). For example, dijit.Menu ends up directly under the BODY tag, irrespective of where it was originally defined in the node hierarchy. Tracing the parentage from a dijit.getId() within the DOM doesn't therefore necessarily return the expected logical result.

I'm just about able to work around this, but it would be really nice if Dojo could include something like node.getDijits() that could return a nodeList of all dijits that are logical descendents of the specified DOM node. Not sure if this would be possible, but it would be extremely powerful, and would save me a lot of messing about. Indeed, come to think of it, what would be even more useful would be node.destroyDescendentDijits() which would recursively destroy all widgets that are logical descendents of the specified DOM node.

sure

Sure, this is a known problem and is documented in #2056, #3300, #4902, #4980. We definitely need a fix to it.