0

i have a table like this:

    <table class="table">
  <thead>
    <tr>
      <th scope="col">Id</th>
      <th scope="col">Name</th>
      <th scope="col">Family</th>
      <th scope="col">Age</th>
    </tr>
  </thead>
  <tbody>

   </tbody>
</table>

<div id="div1">
@foreach(var item in Model)
{
<tr>
      <th>item.Id</th>
      <td>item.Name</td>
      <td>item.Family</td>
      <td>item.Age</td>
</tr>
}
</div>

I want to cut div1 content and paste to table tbody tag with jquery the result that i need is:

  <table class="table">
      <thead>
        <tr>
          <th scope="col">Id</th>
          <th scope="col">Name</th>
          <th scope="col">Family</th>
          <th scope="col">Age</th>
        </tr>
      </thead>
      <tbody>
          @foreach(var item in Model)
    {
    <tr>
          <th>item.Id</th>
          <td>item.Name</td>
          <td>item.Family</td>
          <td>item.Age</td>
    </tr>
    }
       </tbody>
    </table>

also i use this code but doesn't work:

<script>
    $(document).ready(function () {
        $("#div1").replaceAll("tbody");
    }
</script>

I tried with some jquery method but mostly copy all div(div tag with content) but i need only cut content of div. please help me

1 Answers1

0

This might help you.

$('#div1').contents().appendTo('tbody')
Sachin Gaur
  • 12,909
  • 9
  • 33
  • 38