Instead of checking classes you can check the original checkbox, and get the button description from the parent.
Side note, I use ifToggled
event so it will be fired for checked and unchecked elements.
Code:
$('ul.brands input').each(function () {
var self = $(this),
label = self.next(),
label_text = label.text();
label.remove();
self.iCheck({
checkboxClass: 'icheckbox_line-blue',
radioClass: 'iradio_line',
insert: '<div class="icheck_line-icon"></div>' + label_text
});
});
$('ul.brands input').on('ifToggled', function (event) {
brands();
});
function brands() {
var brands = [];
$('ul.brands input').each(function (index, value) {
if ($(this).is(':checked')) {
brands.push($(this).parent().text());
}
});
console.log(brands);
}