Your problem is that your
inserts after every
the matched set of elements will be inserted after the element(s) specified by this parameter.
You probably just want to use
after on the row you're duplicating. And a little
.find(':text').val('') will clear the cloned text inputs; something like this:
var $tr = $(this).closest('.tr_clone'); var $clone = $tr.clone(); $clone.find(':text').val(''); $tr.after($clone);
Demo: http://jsfiddle.net/ambiguous/LAECx/ or for a modern jQuery: http://jsfiddle.net/ambiguous/LAECx/3274/
I'm not sure which input should end up with the focus so I've left that alone.
~ Answered on 2011-11-01 02:41:48