I'm doing maintenance on a system, and I found the following code:
$(".MinhaClass").die();
$(".MinhaClass").live('click', function () {
// Código
}
.MinhaClass
refers to a list of checkbox
. I was asked to add a checkbox
to the list Everyone at the top of the list. I soon thought of doing:
$("#selecionar-todos").change(function () {
$('#lista input:checkbox').each(function () {
$(this).click();
});
});
Soon the system would behave in the same way as before, without many changes. When you click select all, all items in the list are checked, including the "Select All" checkbox, but when you click on an item individually, it is unchecked and the "Select All" checkbox should also be unchecked. Home For this, it would be necessary to identify in the first code where the click action comes from, if it was called by the method that I created or was triggered by the mouse click individually. I have this Fiddle to explain it better.
Note: The problem is that the Select All checkbox should only be marked when all items are checked, if any unchecked, the select all checkbox should also be unchecked ...