var range; function add(html, id) { const old = document.getElementById(id) if (old !== null) { old.remove() } if (range === undefined) { var range = document.createRange() range.setStart(document.body, 0) } document.body.appendChild( range.createContextualFragment(html) ) }