tags:

views:

106

answers:

3

I have a form that I'm trying to duplicate using jQuery. I'm using the clone() method, which returns the cloned object (DOM element). I need to then select elements of the cloned form and manipulate them. Is this possible? If so, how?
I've tried stuff like:

var clonedForm = $("#myForm").clone();
clonedForm.$(".inputField").val();

But (unsurprisingly) the second line doesn't work. Any help would be appreciated, thanks.

+3  A: 

I think

$(clonedForm).find('.inputField').val()
gene tsai
This works great for the object's descendants (which I do need), but I also need to be able to operate on the 'main' element (the one I'm calling clone() on). e.x.: I'm cloning a div and I need to change that div's ID
Arms
I forgot about the attr() method. Between your solution and this method I'm all set. Thanks
Arms
A: 

Well first what you get from the clone method is a piece of DOM that needs to be attached somewhere to be visible (it's not obvious from your code snippet if that's the case). Second - if you are using same IDs fir your elements you out of luck since findElementBYID will return you fisrt element it will find. You probably need go through your clone object ans change ID values. And then your syntax is also wrong in the second line as been pointed out

DroidIn.net
+1  A: 

If you want to change the Id of the element you are cloning, try this

var clonedForm = $("#myForm").clone();

clonedForm.attr( { id: 'new-id' } );
alex