guys i have a function which when used it should check all the boxes and uncheck them. this was the original one that works great
     $('#checkAllId').change(function(){
    if($(this).attr('checked')){
     //uncheck all the checkboxes   
     $("input[type='checkbox']").each( 
       function() { 
          $(this).attr('checked',false);
       } 
     );
   }else{
      //check all the checkboxes  
      $("input[type='checkbox']").each( 
       function() { 
          $(this).attr('checked',true);
       } 
     ); 
   }
});  
however i adapted the function so i could target specific checkboxes with a certain class. here is the adapted version
    $('#checkAllId').change(function(){
    if($(this).attr('checked')){
     //uncheck all the checkboxes   
     $("input.mainobservations:checkbox").each( 
       function() { 
          $(this).attr('checked',false);
       } 
     );
   }else{
      //check all the checkboxes  
      $("input.mainobservations:checkbox").each( 
       function() { 
          $(this).attr('checked',true);
       } 
     ); 
   }
});  
This works to check all the boxes but it doesnt not work to uncheck all the boxes. Why is this?
 
     
     
     
    