click if/else problem
click if/else problem
Good afternoon.
I am new to javascript and brand new to jQuery.
I have little snippet I wrote to show or hide various <div>'s when a checkbox is clicked, depending on whether or not the checkbox is checked.
There are 5 categories of information being displayed in a table, and the idea is that the user can un-check a box to hide a category, and re-check the box to show the category. There is also a 'show all' checkbox that will show all of the div's.
The code I am using is as follows:
-
$("#cal-all").click(function(){
if($(this).attr("checked" == true)){
$("#cal-all").attr("disabled", "disabled");
$("#cal-head input:not(#cal-all)").attr("checked", "checked");
$("table.calendar div").show();
}
});
$("#cal-head input:not(#cal-all)").click(function(){
var classMatch = $(this).attr("id");
if($(this).attr("checked" == false)){
$("div." + classMatch).hide();
$("#cal-all").attr("checked", "");
$("#cal-all").attr("disabled", "");
}
else{
$("div." + classMatch).show();
}
});
Everything works as I want it to except for the last part - the 'else'.
When a box is unchecked, the corresponding div's are hidden.
When I click the 'show all' checkbox, all div's are shown.
But when I check a checkbox that had been un-checked, the corresponding div's are
not shown.
Can anyone tell me what I may be doing wrong?
Any help greatly appreciated!