Есть таблица в которой в одной из колонок стоят чекбоксы для выбора строки
<table class="table table-bordered table-checks">
<thead>
<tr>
<th>
<div id="all" class="checker">
<span>
<input id="all" class="styled" type="checkbox" name="checkRow" style="opacity: 0;">
</span>
</div>
</th>
<th>ID</th>
<th>Автар</th>
<th>Название</th>
<th>URL</th>
<th>Дата создания</th>
<th>Статус</th>
</tr>
</thead>
<tbody>
<?php foreach($latest_materials as $item): ?>
<tr data-id="<?=$item['material_id']?>">
<td>
<div id="" class="checker">
<span>
<input class="styled" type="checkbox" name="checkRow" style="opacity: 0;">
</span>
</div>
</td>
<td>
<?=$item[ 'material_id']?>
</td>
<td>
<?=$item[ 'author']?>
</td>
<td>
<?=$item[ 'title']?>
</td>
<td>
<?=$item[ 'material_id']?>
</td>
<td>
<?=$item[ 'date']?>
</td>
<td></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
когда выбираешь одну строку или несколько рисуется галочка, с помощью jquery добавляться класс .checked { background-position: -17px 0px;}
$(document).on('click','input:checkbox',function(e) {
if($(this).is(':checked')){
$tr = $(this).parents('span');
$tr.addClass('checked');
} else {
$tr = $(this).parents('span');
$tr.removeClass('checked');
}
Но я не могу добиться когда нажимаешь на чекбокс в шапке таблицы, чтоб добавлялся класс checked во все span таблицы. И я не уверен что и этот код jquery написал правильно хотя он и работает.