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.

200_success
145k22 gold badges190 silver badges478 bronze badges
asked May 18, 2011 at 13:51
\$\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\$ Commented May 18, 2011 at 13:59

1 Answer 1

6
\$\begingroup\$

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

answered May 18, 2011 at 16:50
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.