Seems like a really simple question, but I can't find a solid answer for it no matter where I search =( It might be an obvious answer but it just bothers me until I can be sure.
I have this:
someDiv.innerHTML = "Some <span style='color:red'>" + var + "</span> text from variable";
however later on when a user changes some things, it might not require the variable so it transforms to:
someDiv.innerHTML = "A simple sentence";
so my question is, does the previous span get removed automatically? I don't have to worry about tons of <span>'s
being somewhere to never be heard of or seen from again? =)
Thanks for clearing out any confusion for me and sorry in advance for the trouble. Thanks again for any help.
Assigning string to innerHTML completely erases old content of the DOM element. So the answer is yes! When the spans you mentioned are removed from the DOM tree, their memory footprint left to the browser's garbage collector, and you should not worry about them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With