• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

TypeError: Cannot read property 'getElementsByClassName' of null

Scheduled Pinned Locked Moved Troubleshooting
4 Posts 3 Posters 9.3k Views 3 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    Mr.Sponti
    last edited by Dec 28, 2016, 9:05 AM

    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!

    S 1 Reply Last reply Dec 28, 2016, 10:52 AM Reply Quote 0
    • S Offline
      strawberry 3.141 Project Sponsor Module Developer @Mr.Sponti
      last edited by Dec 28, 2016, 10:52 AM

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

      Please create a github issue if you need help, so I can keep track

      1 Reply Last reply Reply Quote 0
      • M Offline
        MichMich Admin
        last edited by Dec 28, 2016, 12:38 PM

        Try addicting this method to your module:

        notificationReceived: function(notification, payload) {
            if (notification === 'DOM_OBJECTS_CREATED') {
                // you can now schedule the dom update method.
            }
        }
        
        1 Reply Last reply Reply Quote 0
        • M Offline
          Mr.Sponti
          last edited by Dec 28, 2016, 7:52 PM

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

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            1/4
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Sam, technical setup by Karsten.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy