ceiling cat
ceiling cat

Reputation: 5701

How to wait until an element exists for dojo?

In dojo, is there a way to get notified when an element of certain class (or contain certain text) has been created?

There is an almost exactly the same question asked in here for jQuery. But I'd like to know if there is a similar solution for dojo. Thank you!

Upvotes: 7

Views: 1295

Answers (1)

Philippe
Philippe

Reputation: 6828

For dojo 1.7, based on the JQuery answer, I would do :

require(["dojo/on", "dojo/_base/array"], function(on, array){
    on(dojo.doc, "DOMNodeInserted", function(evt){
        var classes = dojo.attr(evt.target, "class").split(" ");
        if (array.indexOf(classes, "myclass") > -1) {
            console.debug("Inserted node with class myclass", evt.target);
        }
    });
});

Upvotes: 6

Related Questions