There is a table in which in one of the columns are checkboxes for row selection
<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> when you select a single line or a tick is drawn, the class .checked { background-position: -17px 0px;} added using jquery
$(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'); } But I can not achieve when you click on the checkbox in the header of the table to add the checked class to all table spans. And I'm not sure that this jquery code has written correctly even though it works.