> Meaning, is this following valid? > > var inputBox = $('<input>').attr("type", "text").attr("id", > "someText"); > . > . > inputBox.appendTo('#myForm'); > inputBox.appendTo('#myForm'); > inputBox.appendTo('#myForm'); > > In my testing, that doen't work. It only adds the first one.
A single node can't appear twice in the DOM. But you can easily clone a node. http://docs.jquery.com/DOM/Manipulation#clone.28_deep_.29 First, let's call your variable $inputBox instead of inputBox so I won't get confused. :-) (A common - and helpful - convention is to use a $ prefix on a variable containing a reference to a jQuery object, as a reminder that it's a jQuery object.) Then, do a deep clone of $inputBox each time you want to append it: $inputBox.clone(true).appendTo('#myForm'); $inputBox.clone(true).appendTo('#myForm'); I think that should do the trick. -Mike