TypeError: Cannot read property 'getElementsByClassName' of null



  • Hi,
    I’m at my wit’s end!
    Based on module “MMM-FHEM by BenRoe” I’ve created a module to receive event changes from the home automation pimatic. The module works fine. Then I started to write a second modul and can’t get rid of the error:
    Cannot read property ‘getElementsByClassName’ of nullt

    To isolate the problem I reduced the code to the example from the module development page.

    Module.register("HelloWorld",{
        // Default module config.
        defaults: {
            text: "Hello World!"
        },
        
        start: function() {
            var self = this;
            setInterval(function() {
                self.updateDom(); // no speed defined, so it updates instantly.
            }, 1000); //perform every 1000 milliseconds.
        },
        // Override dom generator.
        getDom: function() {
            var wrapper = document.createElement("div");
            wrapper.className = 'MyHelloWorld';
            wrapper.innerHTML = this.config.text;
            return wrapper;
        }
    });
    

    Following the console log:

    alt text

    What’ s wrong? I need help from an expert!



  • @Mr.Sponti that happens because you are trying to update the DOM before its even created


  • MagicMirror Creator

    Try addicting this method to your module:

    notificationReceived: function(notification, payload) {
        if (notification === 'DOM_OBJECTS_CREATED') {
            // you can now schedule the dom update method.
        }
    }
    


  • @MichMich: Thank’s a lot, I’ve fixed the issue. Result can be reviewed here


Log in to reply
 

Looks like your connection to MagicMirror Forum was lost, please wait while we try to reconnect.