Are you by any chance appending it with some additional text?
For example, something like this:

$('#clonehere').append($('.hook:first').clone(true) + "<br />");

If you do that then you will get [object Object]

The code works fine as it is, as long as you use it correctly; here's
a page using your markup and your code:

http://actingthemaggot.com/test/clone_test.html

No workaround is needed.

On Mar 5, 9:12 am, bstoppel <brett.telosstud...@gmail.com> wrote:
> The code works, but not as I need it to. If I remove the .html() and
> append the clone to another element, I get an object, not the form. I
> need the form. As Rick and another person the I spoke with mentioned,
> a work around is to wrap the form with a div and select the div. That
> way when I .clone() the div and get the .html(), the innerHTML
> contains the form tag. I am not a huge fan of adding cruft to my HTML,
> but it is time to accept the solution at hand and move on. Even if it
> is not perfect.
>
> Thanks everyone.
>
> On Mar 5, 10:23 am, mkmanning <michaell...@gmail.com> wrote:
>
> > Your code works fine without the .html(). If you're trying to log what
> > you get, then it will say 'object', which is to be expected.
>
> > On Mar 5, 8:18 am, "Rick Faircloth" <r...@whitestonemedia.com> wrote:
>
> > > Possible work-a-around...
>
> > > Enclose your form in a div, say "<div id='form-div'>form...</div>,
> > > and clone the div...?
>
> > > Rick
>
> > > -----Original Message-----
> > > From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
>
> > > Behalf Of bstoppel
> > > Sent: Thursday, March 05, 2009 11:07 AM
> > > To: jQuery (English)
> > > Subject: [jQuery] Re: .clone a form
>
> > > Without the .html() part you get an object. With .text() you get what
> > > appears to be HTML entities and text.
>
> > > On Mar 5, 6:10 am, "Rick Faircloth" <r...@whitestonemedia.com> wrote:
> > > > Not sure, but it might be that the .html() part is telling the clone
> > > > function to just clone the html *within* .hook:first.
>
> > > > What happens if you leave off the .html() part?
>
> > > > Rick
>
> > > > -----Original Message-----
> > > > From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com]
> > > > O
>
> > > > Behalf Of bstoppel
> > > > Sent: Wednesday, March 04, 2009 11:50 PM
> > > > To: jQuery (English)
> > > > Subject: [jQuery] .clone a form
>
> > > > Hi All.
>
> > > > I am having an issue with cloning a form. When I clone an existing
> > > > form, only the input tags are cloned. Here is an example"
>
> > > > -- HTML
>
> > > > <form class="hook" action="do/something" method="post"
> > > > enctype="multipart/form-data">
> > > > <input type="text" name="variable">
> > > > <input type="submit">
> > > > </form>
>
> > > > <div id="clonehere"></div>
>
> > > > -- JQuery
>
> > > > $('#clonehere').append($('.hook:first').clone(true).html());
>
> > > > -- Result
>
> > > > #clonehere will only get this part of the form <input type="text"
> > > > name="variable"> <input type="submit">
>
> > > > What am I doing wrong?

Reply via email to