Hi, I need to find a way to clone an all form and its content using the prototype.js framework. I''ve found many scripts like this one : <script type="text/javascript"> Element.addMethods({ clone: function(element) { var newElm = $($(element).cloneNode(true)); return newElm; } }); </script> But it seems that I can only clone one element at a time. What about if I need to clone my form element and all it''s childNodes ? Thanks a lot for your help. P.S. : I tried to make a recursive function but can''t make it to work: superClone: function(element) { var newElm = $($(element).cloneNode(true)); if ($(element).hasChildNodes()){ $A($ (element).childNodes).each(newElm.appendChild(Element.clone())); //$A($(element).childNodes).each(Element.remove); } return newElm; } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Jun 26, 2008 at 10:58 AM, dhjapan <Leon.Ronssin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > I need to find a way to clone an all form and its content using the > prototype.js framework.Does it have to be Prototype? The DOM cloneNode function could very well work: $(''el'').cloneNode(true); // the "true" parameter copies child elements as well More here: http://developer.mozilla.org/en/docs/DOM:element.cloneNode :Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
My bad, .cloneNode(true) works really fine. I actually mad a big mistake : a few lines above I was emptying the cloned node instead of the one I wanted to clone my form into. Thanks a lot and sorry I''ve wasted your time. dhjapan On Jun 26, 7:27 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Jun 26, 2008 at 10:58 AM, dhjapan <Leon.Rons...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > I need to find a way to clone an all form and its content using the > > prototype.js framework. > > Does it have to be Prototype? The DOM cloneNode function could very well work: > > $(''el'').cloneNode(true); // the "true" parameter copies child elements as well > > More here:http://developer.mozilla.org/en/docs/DOM:element.cloneNode > > :Dan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
FYI if you''re going to insert the result of cloneNode() into your document, make sure none of the elements under the original node has an ID. The IDs will be duplicated (I think) and $() will start getting all confused. -Fred On Thu, Jun 26, 2008 at 1:16 PM, dhjapan <Leon.Ronssin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > My bad, > .cloneNode(true) works really fine. > I actually mad a big mistake : a few lines above I was emptying the > cloned node instead of the one I wanted to clone my form into. > > Thanks a lot and sorry I''ve wasted your time. > > dhjapanIt''s not a waste of time as long as you learn something. :) -- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---