$(document).ready(function() {
$(".chk").click(function() {
$(".chk:checked").each(function() {
$("."+this.id).show();
});
$(".chk:not(:checked)").each(function() {
$("."+this.id).hide();
});
// give a message if nothing left to show
});
});
<label>
<input class="chk" type="checkbox" checked="checked" id="course">Courses
</label>
<label>
<input class="chk" type="checkbox" checked="checked" id="morning">Morning
</label>
<label>
<input class="chk" type="checkbox" checked="checked" id="evening">Evening
</label>
<ul>
<li class="courseBox course">Course</li>
<li class="courseBox course evening">Course, Evening</li>
<li class="courseBox morning">Morning </li>
</ul>
How do I most elegantly know if all the affected divs were hidden?
UPDATE: If you need to check after a fadeOut, you need to put the check in the callback:
$(".chk:not(:checked)").each(function() {
$("."+this.id).fadeOut(function() {
if (!$('.courseBox:visible').length) {
alert('all are hidden');
}
});
});
http://jsfiddle.net/JrAhR/6/