I have a table that has rows of bugs. Each row, has a class assigned to it based on the scrub status of the bug.
<tr class="bugrow wait_dev"> <td>blah</td></tr>
<tr class="bugrow wait_support"> <td>blah</td></tr>
<tr class="bugrow wait_branch"> <td>blah</td></tr>
I am using Bootstrap to create a button list for each of the different statuses. The buttons are really just checkboxes in HTML.
<input class="scrub_checkbox" id="wait_dev" type="checkbox" autocomplete="off">Wait dev
<input class="scrub_checkbox" id="wait_support" type="checkbox" autocomplete="off">Wait support
<input class="scrub_checkbox" id="wait_branch" type="checkbox" autocomplete="off">Wait branch
What I want to do, is have a jQuery function where when a button is clicked (and the underlying checkbox is selected) all rows that do not have the corresponding class, are hidden leaving only the selected rows visible.
I want to be able to click/select multiple options, and have all of those row types shown, and all else hidden.
How can I do this in jQuery?
Solution
I came up with a solution based off of TrueBlueAussie's OR option. This will show all rows once none of the checkboxes are selected.
$('.scrub_checkbox:checkbox').change(function(){
// Build a list of comma-separated classes
var classes = ""
// for each checked box with class scrub_checkbox
$('.scrub_checkbox:checkbox:checked').each(function(){
if (classes) classes += ",";
classes+= "." + $(this).attr('id');
});
if (classes){ // if there are classes to show
$('.bugrow').hide().filter(classes).show();
} else { // nothing checked, show all
$('.bugrow').show();
}
});