1 2 3 I want to clone it and add parent to it to be like this 1 2 3 I want to clone it and add parent to it to be like this 1 2 3 I want to clone it and add parent to it to be like this

clone element jQuery and add parent <tbody> before this element

169 views Asked by At

I have this element

<tr class="group-row">
  <td>1</td>
  <td>2</td>
  <td>3</td>
</tr>

I want to clone it and add <tbody> parent to it to be like this

<tbody>
  <tr class="group-row">
    <td>1</td>
    <td>2</td>
    <td>3</td>
  </tr>
</tbody>
1

There are 1 answers

0
amine laksir On

something like this should work :

var $clone = $("#element-to-clone").clone();
$("#where-you-want-to-put-the-clone").append($clone);
$clone.wrap( "<tbody></tbody>" );