var count = 0; function newElement() { var elem = document.createElement('foo:bar'); var text = document.createTextNode('Node ' + ++count); elem.appendChild(text); document.lastChild.appendChild(elem); }