You are here

Example of simple jsTree with tri-state checkbox

Submitted by Asif Nowaj, Last Modified on 2019-11-08

jsTree is jquery plugin, that provides interactive trees. jsTree is easily extendable, themable and configurable. One of noticeable feature is its tri-state checkbox. States are checked, unchecked and indeterminate.
Indeterminate state is when not all child items are checked then the check state of the parent becomes indeterminate.

Like below, the state of "Root node 2" is Indeterminate as not all child nodes are checked.

jsTree With Indeterminate State

Once 'checkbox' is added as a plugin, you will get the below default jsTree.

jsTree With default checkbox

Code file is below, so that you copy it and can be tested.

<!DOCTYPE html>
<html lang="en" xmlns="">
    <meta charset="utf-8" />
    <title>Simple jsTree with tri-state checkbox</title>
    <link rel="stylesheet" href="" />
    <script src=""></script>
    <script src=""></script>
    <script type="text/javascript">
        $(function () {

            var jsondata = [
                           { "id": "ajson1", "parent": "#", "text": "Simple root node" },
                           { "id": "ajson2", "parent": "#", "text": "Root node 2" },
                           { "id": "ajson3", "parent": "ajson2", "text": "Child 1" },
                           { "id": "ajson4", "parent": "ajson2", "text": "Child 2" },


        function createJSTree(jsondata) {
                "core": {
                    "check_callback": true,
                    'data': jsondata                    
				"checkbox" : {
					"keep_selected_style" : false
                "plugins": ["checkbox"]
    <div id="SimpleJSTree"></div>

Now if you click on "Root node 2", it will automatically check all its child nodes as shown below.

jsTree With checkbox checked

Discussion or Comment

If you have anything in mind to share, please bring it in the discussion forum here.