I\'m brand new to Javascript and JQuery, so I\'ve been reading up on it and am trying to check (and set inactive) a checkbox in a parent list-item when one of the children a
Check this fillde
$("input:checkbox + ul input:checkbox").click(function(){
var $ul = $(this).closest("ul");
var $parent = $ul.prev("input:checkbox");
if($ul.find("input:checkbox:checked").length > 0){
$parent.attr("checked", "checked");
}else{
$parent.attr("checked", "");
}
})
If you are using the id
property for elements, you have to make sure that it has a unique value in the document.