1

I want to delete all <div> which id begins with xyz from the dom tree.

I know that this can be done with dojo.query and dojo.destroy but I never used this combination before.

I tried this but it doesn't work:

var divNodesWidgets = dijit.findWidgets('[id^="divNodes"]');
dojo.forEach(divNodesWidgets, function(d) {
    d.destroyRecursive(true);
});

var UlWidgets = dijit.findWidgets('[id^="ulNodes"]');
dojo.forEach(UlWidgets, function(u) {
u.destroyRecursive(true);
});

var headingWidgets = dijit.findWidgets('[id^="h1Nodes"]');
dojo.forEach(headingWidgets, function(h) {
h.destroyRecursive(true);
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2219190
  • 157
  • 2
  • 13

3 Answers3

2

Is what you are destroying a widget or just an Element, if its just an element try with:

    dojo.forEach(dojo.query('[id^="xyz"]'), function(entry,idx){
     dojo.destroy(entry);
    alert(entry + " Destroyed");
});

or

dojo.query('[id^="xyz"]').forEach(dojo.destroy);
tik27
  • 2,698
  • 1
  • 16
  • 25
  • the answer comes late, sorry. i want to destroy widgets. i edited my post above with some code – user2219190 May 24 '13 at 08:27
  • What ive used in the past that seems to work is a combo of. entry.destroyDescendants() and entry.destroy(). – tik27 May 27 '13 at 13:19
0

You have to use Jquery Attribute Starts With Selector [name^="value"]

http://api.jquery.com/attribute-starts-with-selector/

Please go through this and you will get to know what you have to do

Sujith Wayanad
  • 543
  • 6
  • 20
0

I just add this answer for the sake of using AMD syntax, since you are using dojo 1.8.3, otherwise I would go for tik27's second proposal.

require(["dojo/query", 
         "dojo/dom-construct", 
         "dojo/domReady!"
], function(query, domConstruct){
    query("div[id^='xyz']").forEach(domConstruct.destroy);
});

See http://dojo-sandbox.net/psoares/2a702/1

Philippe
  • 6,703
  • 3
  • 30
  • 50