A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.
Read the statement by Michael Teeuw here.
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"); wrapper.appendChild(t); wrapper.appendChild(img); 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?
Thanks!
-
@Synthic
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"); t.id = "textarea"; t.innerHTML = "text"; // ... var u = document.getelementbyid("textarea"); u.innerHTML = "updated text";