I have a HTML table in my MVC View.
Here is the code of this table:
<table class="table" >
@{int rowNo = 0;}
<tr>
<td data-toggle="modal" data-target="#newAppointment" style="height: 40px; width: 40px; background: red;">
<img style="object-fit: cover;" src='@Url.Content("~/Images/plus.png")'/>
</td>
</tr>
<tr style="background: white">
<th></th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
Date of birth
</th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
Last Name
</th>
<th style="font-size: 20px; text-align: center;color:#1d69b4;">
First Name
</th>
</tr>
@foreach (var item in Model)
{
<tr id="patients">
<td class="point">
@(rowNo += 1)
</td>
<td class="title">
@Html.DisplayFor(modelItem => item.Date_of_Birthday)
</td>
<td class="title">
@Html.DisplayFor(modelItem => item.Last_name)
</td>
<td class="title">
@Html.DisplayFor(modelItem => item.First_name)
</td>
</tr>
}
</table>
I need to delete all the rows in the table, so I need to delete everything in patients.
I tried to do it like the following via JS, but it only deletes the first row:
<script>
$('#search').click(function () {
$("#patients").remove();
});
</script>
How can I delete all the rows?
id=patientsis a<tr>element and its invalid html because of the duplicateidattributes. Add a<thead>and<tbody>element with anidattribute and remove the<tr>elements from the<tbody>using.empty()