1
\$\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
    \$\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 '11 at 13:59
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, privacy policy and cookie policy

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