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";
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login