fancy
fancy

Reputation: 51463

How can I clone everything in a div without cloning the outer div?

I'd like to use jQuery.clone() but I only want to copy the inner elements, not the element itself. If needed I can wrap the contents but I was hoping to find another way to just clone the inner html.

Thanks.

Upvotes: 2

Views: 1225

Answers (2)

Joseph Marikle
Joseph Marikle

Reputation: 78590

Yup, you can use .children().clone()

http://jsfiddle.net/pR6ve/1

Upvotes: 3

lonesomeday
lonesomeday

Reputation: 238115

You need to use contents to get all the child nodes (and their descendants):

$('#foo').contents().clone(true).appendTo('#bar');

Upvotes: 2

Related Questions