Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
189
rated 0 times [  191] [ 2]  / answers: 1 / hits: 70666  / 14 Years ago, sun, february 20, 2011, 12:00:00

I have a div that is filled by JS created DOM elements,



I want the div to be cleared upon the JS function repeating, however I have heard that using document.getElementById('elName').innerHTML = ; is not a good idea,



What is a valid alternative to doing this to clear the div's contents?


More From » html

 Answers
33

If you have jQuery then:



$('#elName').empty();


Otherwise:



var node = document.getElementById('elName');
while (node.hasChildNodes()) {
node.removeChild(node.firstChild);
}

[#93662] Thursday, February 17, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daijab

Total Points: 60
Total Questions: 99
Total Answers: 110

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
;