Skip to content

Instantly share code, notes, and snippets.

@neopunisher
Created September 29, 2011 17:43
Show Gist options
  • Save neopunisher/1251383 to your computer and use it in GitHub Desktop.
Save neopunisher/1251383 to your computer and use it in GitHub Desktop.
list checkbox tree with indeterminate
jQuery.fn.reverse=[].reverse;jQuery(".nc>input:checkbox").click(function(){$this=jQuery(this);$this.parent().find("ol").find("input:checkbox").attr("checked",$this.is(":checked"))});
jQuery("input:checkbox").click(function(){jQuery(this);jQuery("li.nc>input:checkbox").reverse().each(function(b,d){var a=jQuery(d),c=a.parent().find("input.cu");a.attr("rel",b);a.prop("indeterminate",!1);c.length==c.filter(":checked").length?(console.log("all checked:"+b),a.attr("checked",!0)):c.length==c.filter(":not(:checked)").length?(console.log("all unchecked:"+b),a.attr("checked",!1)):(console.log("indeterminate:"+b),a.prop("indeterminate",!0))})});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment