document.write("
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Adding and removing a class using jQuery</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(function(){
$('input:checkbox').change(function(){
var row = $(this).closest('tr');
if($(this).is(":checked")) {
row.addClass("bg-success");
} else {
row.removeClass("bg-success");
}
});
});
</script>
</head>
<body>
<div class="container">
<table class="table table-bordered">
<thead>
<tr>
<th>Check</th>
<th>ID</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" id="check1"></td>
<td>1</td>
<td>Bob</td>
</tr>
<tr>
<td><input type="checkbox" id="check2"></td>
<td>2</td>
<td>Sally</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
225.html - Snippet hosted by \"Cacher\"
");