I have a function that is run on a generic table, it can't be specific, it needs to be able to be run on many different tables. The problem I'm having is if it's run on multiple tables on the same page. The click events fire just fine, but they only operate on the check elements in the final table, not the check elements within the table they were supposed to work on.
Here's the code:
$parent = $table.parents('div.ibox').find('div.ibox-title');
$select_all = $parent.find('button.select_all');
$deselect_all = $parent.find('button.deselect_all');
$input_delete = $table.find('input.delete');
if ($table.find('input.delete').length >= 2) {
$select_all.removeClass('hidden');
} else {
$select_all.addClass('hidden');
$deselect_all.addClass('hidden');
}
$select_all.on('click', function(event) {
$input_delete.each(function() {
$(this).prop('checked', true).trigger('change');
$select_all.addClass('hidden');
$deselect_all.removeClass('hidden');
});
});
$deselect_all.on('click', function(e) {
$table.find('input.delete:checked').each(function() {
$(this).prop('checked', false).trigger('change');
$deselect_all.addClass('hidden');
$select_all.removeClass('hidden');
});
});
$table
is a variable containing the $('table')
element the function is being run on, it's passed into the function.
Just wondering if anyone has any ideas on how to get the click elements to fire on the checkboxes within the table they are supposed to, and not the final table on the page.