I want to select all the checkboxes in table on clicking the header checkbox. I don't know how to do that. This is what I have done so far.
<table class="table" id="myTable">
<thead>
<tr>
<th>
<input type="checkbox" id="selectAll" />
</th>
<th>
@Html.DisplayNameFor(model => model.SNumber)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>
<th>
@Html.DisplayNameFor(model => model.Quantity)
</th>
<th></th>
</tr>
</thead>
@foreach (var item in Model)
{
@Html.HiddenFor(model => item.PartNumber)
<tr>
<td>
@Html.CheckBoxFor(modelItem => item.Transfer)
</td>
<td>
@Html.DisplayFor(modelItem => item.SNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantity)
</td>
<td>
@Html.ActionLink("Edit", "EditDetails", new { id = item.PartNumber }) |
@Html.ActionLink("Delete", "Delete", new { id = item.PartNumber }, new { onclick = "return confirm('Are sure wants to delete?');" })
</td>
</tr>
}
<script>
$('#selectAll').click(function (e) {
$(this).closest('table').find('td input:checkbox').prop('checked', this.checked);
});
</script>
This is what the console is returning :
Uncaught ReferenceError: $ is not defined
How do I get past it? I am new to MVC. Any and all help will be appreciated.