Created
August 25, 2015 12:05
-
-
Save nekitozzz/15483f3867a1b564d8c4 to your computer and use it in GitHub Desktop.
Select/deselect all checkboxes using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var checkboxList = this.$el.find('.b-filter-dialog__params').filter(':has(.selectall)'); | |
checkboxList.each((index, element) => { | |
var $element = $(element); | |
var allCheckbox = $element.find('.selectall'); | |
var regularCheckboxes = $element.find(':checkbox').not('.selectall'); | |
allCheckbox.click(function() { | |
regularCheckboxes.attr('checked', this.checked); | |
}); | |
// Если выделены все чекбоксы выделить чекбокс "все" | |
regularCheckboxes.click(() => { | |
if (regularCheckboxes.length === regularCheckboxes.filter(':checked').length) { | |
$('.selectall').attr('checked', 'checked'); | |
} else { | |
$('.selectall').removeAttr('checked'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment