Selecting a dynamically created element

Selecting a dynamically created element

I have a text box im dynamically adding to the dom created with this line of code

$("<input />").attr("type", text).attr("value", text).attr("class", "wrong").attr("id", id);


When I try to get the value of the text box by referring to its id. I get an "undefined". I can get the value if I use plain javascript.

alert($("#" + parentId + ".idtxt").val());

alert(document.getElementById(parentId + ".idtxt").value);


Any ideas?