Suppose I have the following code:
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
Now when I do, $("ul").clone();
, it clones the full ul
element (all its children also).
I want only to clone <ul>
and not its children.
How to do that in jQuery?
I know in pure JavaScript (using cloneNode()
), but I can't use this because of additional methods to perform also.
')` than to clone the element (including its children) and then remove its children, as several answer have suggested.
– user229044 Apr 21 '14 at 14:08