function first() { var elem = document.getElementById('id'), input = document.createElement( 'input' ); input.type = "submit"; input.value = 'Ok'; input.onclick = function() { return second(elem); } elem.appendChild( input ); }