MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

How to only update specific parts of DOM

  • Hey there.

    I’m working on my own module where my DOM consists of some text and an animated gif.

    What I want to do is to change the text without refreshing the animated gif.

    This function is called with the appropriate argument from the getDom() function:

    createHTML: function(text) {
            var wrapper = document.createElement("div");
            var t = document.createElement("div");
            t.innerHTML = text;
            var img = document.createElement("IMG");
            img.src = this.file("glowing-ring.gif");
            return wrapper;

    Is there any way to achieve this? I assume the system update the dom because the object returned is a whole new object. Would it work to retrieve the current DOM and simply change the innerHTML of the div and then return the same object. Would the system then recognize that only the text is changing?


  • Module Developer

    Call the text div directly. But since document.getelementsbytagname is messy (as is document.getelementsbyclassname) you should give this div an ID.

    var t = document.createElement("div"); = "textarea";
    t.innerHTML = "text";
    // ...
    var u = document.getelementbyid("textarea");
    u.innerHTML = "updated text";

Log in to reply