function create(name, id) { var node = document.createElement(name); node.id = id document.body.appendChild(node) } create('div', 'elemId'); var a = document.getElementById('elemId') alert(a)