mardi 8 novembre 2016

jquery code optimization for a checked or not checked input

I have this code which take all checks of my table and set them checked, Im trying to rewrite it in a small way, but i don't imagine another, is there such a way?

$('[name=select_todos]').bind('click', function () {
    if ($('[name=select_todos]').is(':checked')) {
        $('#dataTableListModal tbody tr').each(function () {
            $(':checkbox').prop('checked', true);
        });
    } else {
        $('#dataTableListModal tbody tr').each(function () {
            $(':checkbox').prop('checked', false);
        });
    }
});

The final idea is to make it shorter in the amount of code I use.

Aucun commentaire:

Enregistrer un commentaire