var elem = document.createElement('html:div'); var text = document.createTextNode('Node!!!'); elem.appendChild(text); var added = false; dump('elem.id = ' + elem.getAttribute('id') + '\n'); function addElement() { if (! added) { document.lastChild.appendChild(elem); added = true; // should be the same as elem.id... dump('document.lastChild.lastChild.id = ' + document.lastChild.lastChild.getAttribute('id') + '\n'); } } function removeElement() { if (added) { elem.parentNode.removeChild(elem); added = false; } }