Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 532
ceiling cat Avatar asked Dec 22 '11 21:12

ceiling cat


1 Answers

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);
        }
    });
});
like image 50
Philippe Avatar answered Oct 10 '22 19:10

Philippe