Я использую плагин checkboxTree в связи с плагином cookie для jquery.Моя проблема в том, что я хотел бы установить / снять все куки-файлы дочерних элементов (из заголовка), когда был установлен флажок с классом «заголовок».Как я могу это сделать?Вот мой код .js:
// 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 a cookie of the element exists
if($.cookie(elementId)){
// If so, change attribute to checked
$(this).attr("checked", "checked");
}else{
// If not, change attribute to not checked
$(this).attr("checked", "");
}
});
$(".tree input:checkbox").change(function(){
if($(this).attr("class") == "header"){
if($(this).is(":checked")){
setCookie(this.id);
// Set cookie for all children
}else{
unsetCookie(this.id);
// Unset cookie for all 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'
});
А вот мой HTML-код:
<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>