Skip to content

Instantly share code, notes, and snippets.

@IgorGavrilenko
Created October 5, 2021 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IgorGavrilenko/0afdcd139a79792f63837956d93a24b8 to your computer and use it in GitHub Desktop.
Save IgorGavrilenko/0afdcd139a79792f63837956d93a24b8 to your computer and use it in GitHub Desktop.
группа чекбоксов
<div class="">
<label class="form-label">
<input class="jq-check-all" type="checkbox" data-id="sort">
<span class="form-label__capt">Все</span>
</label>
<label class="form-label">
<input class="jq-check-rest" type="checkbox" data-id="sort">
<span class="form-label__capt"></span>
</label>
</div>
<script>
$(document).ready(function() {
$(".jq-check-all").on("change", function() {
var groupId = $(this).data('id');
$('.jq-check-rest[data-id="' + groupId + '"]').prop("checked", this.checked);
});
$(".jq-check-rest").on("change", function() {
var groupId = $(this).data('id');
var allChecked = $('.jq-check-rest[data-id="' + groupId + '"]:not(:checked)').length == 0;
$('.jq-check-all[data-id="' + groupId + '"]').prop("checked", allChecked);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment