jQuery - Extract text from an appended textbox

$("#id").append( "<input type='text' id ='txt'>" );

// Type something to #txt

// undefined
$("#txt").val()

How to extract what I wrote?