jQuery Checkbox Tree Plugin – New and Improved
Wednesday, July 1st, 2009I have rewritten my jQuery plugin released last year, checkboxtree. A lot of options were asked for in the comments and I have tried to add all of those. Plus the old code made me cringe. I have updated the demos. And I have started a github repository.
The setup is the same. The html should look like this:
<ul class="mytree">
<li>
<input type="checkbox" name="foo" value="whatever" />
<label>Item 1</label>
<ul>
<li>
<input type="checkbox" name="foo" value="whatever" />
<label>Child Item 1</label>
</li>
</ul>
</li>
</ul>
All you need to use checkbox tree is this:
jQuery(document).ready(function(){
jQuery(".mytree").checkboxTree();
})
The options to be passed in as an object are as follows:
| Option | Description |
|---|---|
| collapsedarrow |
(default: "img-arrow-collapsed.gif") The path to the image used to indicate a collapsed row. |
expandedarrow |
(default: "img-arrow-expanded.gif ") The path to the image used to indicate an expanded row. |
blankarrow |
(default: "img-arrow-blank.gif") The path to the image used when there are no child checkboxes. |
activeClass |
(default: "checkboxtreeactive") The class added to the ul when the plugin has been successfully used. |
hoverClass |
(default: "over") The class added to the label on hover for ie6. (only added in ie6) |
checkchildren |
(default: false) If set to false the child checkboxes of the one you select will not be checked. If set to true, child checkboxes will be checked. |
checkparents |
(default: true) If set to true, all parents of a checked checkbox will be checked. |
collapsed |
(default: true) This dictates whether or not the tree will be collapsed or expanded on initial load. |
hidecbwithjs |
(default: false) If this is set to false you will need to hide the checkboxes with css. If true the checkboxes will be hid by the plugin. |
checkedClass |
(default: "checked") This is the class used on the label when a checkbox is in checked state. |