I want to add an Enable all checkbox in an HTML <table>, that toggles all checkboxes inside that <table>.
I can't get it to work.
My Jquery :
var elementName = 'TestName';
$('input[familyname="TestName"]').on('click', function() {
if ($("input[familyname='" + elementName + "']").is(':checked')) {
$(this).find('tr').nextAll('tr').find('input').prop('checked', true);
} else {
$(this).find('tr').nextAll('tr').find('input').prop('checked', false);
}
});
See also this Fiddle.
Update:
I got it to work with this code:
var elementName = 'TestName';
var $checkboxes = $('.table-list').find('input');
$('input[familyname="TestName"]').on('click', function() {
$checkboxes.prop('checked', $(this).is(':checked'));
});
However, there is bug when I want to add more tables. See this Fiddle.