(Note: I\'m using jQuery below, but the question is really a general Javascript one.)
Say I\'ve got a div#formsection
whose contents are repeatedly upda
The documentation on jQuery's empty() method both answers my question and gives me a solution to my problem. It says:
To avoid memory leaks, jQuery removes other constructs such as data and event handlers from the child elements before removing the elements themselves.
So: 1) if we didn't do this explicitly, we'd get memory leaks, and 2) by using empty()
, I can avoid this.
Therefore, I should do this:
formSection.empty();
formSection.html(newContents);
It's still not clear to me whether .html()
would take care of this by itself, but one extra line to be sure doesn't bother me.