Jquery chechboxTree and Cookie plugin - Problem with getting children -


i'm using checkboxtree plugin in relation cookie plugin jquery. problem is, i'd set/unset cookies of children (from header) when checkbox class "header" clicked. how can that? here's .js code:

 // when page has loaded, check each checkbox if it's checked (set cookie) or not (unset cookie)  $(".tree input:checkbox").each(function(){   var elementid = this.id;    // check if cookie of element exists   if($.cookie(elementid)){    // if so, change attribute checked    $(this).attr("checked", "checked");   }else{    // if not, change attribute not checked    $(this).attr("checked", "");   }   });   $(".tree input:checkbox").change(function(){   if($(this).attr("class") == "header"){    if($(this).is(":checked")){     setcookie(this.id);     // set cookie children    }else{     unsetcookie(this.id);     // unset cookie children    }   }else{    if($(this).is(":checked")){     setcookie(this.id);    }else{     unsetcookie(this.id);    }   }  });   function setcookie(element){   $.cookie(element, "checked");  }   function unsetcookie(element){   $.cookie(element, null);  }       $('.tree').checkboxtree({      oncheck: {           node: 'expand'          },          onuncheck: {              node: 'collapse'          },       collapseimage: '../media/images/icons/minus.png',         expandimage: '../media/images/icons/plus.png'     }); 

and here html code:

   <div id="filtertree">      <ul class="tree">          <li><input type="checkbox" id="human ressources" class="header">human resources              <ul>                  <li><input type="checkbox" id="finance">finance                  <li><input type="checkbox" id="personnel">personnel                  <li><input type="checkbox" id="post office">post office                  <li><input type="checkbox" id="house service">house service                  <li><input type="checkbox" id="reception">reception                 </ul>          </ul>     </div> 

  if($(this).attr("class") == "header"){     //selects input of type checkbox within ul li elements, each loops trough list of elements     $(this).parents("ul.tree").find("ul li input:checkbox").each(function() {       if($(this).is(":checked")){  //if item of list checked set cookie, otherwise unset it.         setcookie(this.id);       }       else {         unsetcookie(this.id);       }     });   } 

and remove "," on end of

expandimage: '../media/images/icons/plus.png', 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -