2
\$\begingroup\$

This works:

$('#ShowAll').click(function() {
    if ($(this).prop('checked')) {
        $('tr.hidden').show(); // todo: There's probably some clever toggle that could be used here.
    } else {
        $('tr.hidden').hide();
    }
});

Is there a one-liner I can be doing instead? When the user clicks on the ShowAll checkbox, then show all the rows that have a class of hidden, else hide all the rows that have a class of hidden.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ $('tr.hidden').setHidden(!!$(this).prop('checked')); // or just look for generic method that toggles visibility. Like set css property or something \$\endgroup\$
    – Eimantas
    May 18, 2011 at 13:59

1 Answer 1

6
\$\begingroup\$

.toggle() exists and seems to do exactly what you want here.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.