Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
π« Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download
JavaScript to Empty Something
-
In my tutorial I've this little loop:
while ( div.hasChildNodes() ) { // empty the div div.removeChild( div.firstChild );This works, but is it just the hard way to do this:
div.innerHTML = ''?
-
Completely different things, no? One is removing child nodes from a container element, the other is setting the value of a property of an element.
-
They are the same:
<html><body> <h1> Headline </h1> <button onclick='dump1()'> Dump1 </button> <button onclick='dump2()'> Dump2 </button> <script> function dump1() { alert( document.body.hasChildNodes() ); document.body.innerHTML = ''; alert( document.body.hasChildNodes() ); } function dump2() { alert( document.body.innerHTML ); while ( document.body.hasChildNodes() ) { document.body.removeChild( document.body.firstChild ); } alert( '[' + document.body.innerHTML + ']' ); } </script> </body></html> -
The former used to be the W3C standard way. The latter used to be the non-standard. But as of HTML5 I believe
innerHTMLandouterHTMLare now standard.
Pretty well supported anyway.
Advertisement