• Top 1
    • Sub 1
      • A
      • B
    • " />
      • Top 1
        • Sub 1
          • A
          • B
        • " />
          • Top 1
            • Sub 1
              • A
              • B
            • "/>
              DEVHIDE
              • Home (current)
              • About
              • Contact
              • Cookie
              • Home (current)
              • About
              • Contact
              • Cookie
              • Disclaimer
              • Privacy
              • TOS
              Login Or Sign up

              JSTree font awesome check Box

              2.9k Views Asked by Pavan At 30 May 2018 at 10:47 2025-12-21T06:09:21.849000

              I have a tree structure using jsTree, like this:

              <div id="SampleContainer">
              <ul> 
                <li>
                  Top 1
                  <ul>
                    <li>
                      Sub 1
                      <ul>
                        <li>
                          A
                        </li>
                        <li>
                          B
                        </li>
              
                      </ul>
                    </li>
                    <li>
                      Sub 2
                      <ul>
                        <li>
                          A
                        </li>
                        <li>
                          B
                        </li>
              
                      </ul>
                    </li>
                  </ul>
                </li>
              
              </ul>
              </div>
              

              I would like to put icons of font-awesome for the check-box:

              I tried by doing this:

              $(document).ready(function(){
                 $("#SampleContainer").jstree({
                  "plugins": ["checkbox"],
                  core: {
                    "themes": {
                      "icons": false,
                      "responsive": true
                    }
                  }
                });
                  $('#SampleContainer').on('ready.jstree click', function (e, data) {     
                      $('a > i.jstree-checkbox').removeClass('jstree-icon jstree-checkbox').addClass('fa fa-square-o');
              
                  $('a > i.jstree-clicked').removeClass('jstree-icon jstree-checkbox').addClass('fa fa-check-square');
                    });     
                     });
              

              and this icon 'fa fa-square-o' is coming. not able see the onclick 'fa fa-check-square'.!

              sample Design: enter image description here

              Developed Screen: enter image description here

              Does anyone have an idea about this issue?

              javascript jquery html jstree jstree-search
              Original Q&A
              2

              There are 2 best solutions below

              1
              Guillaume Georges Guillaume Georges On 30 May 2018 at 11:16 BEST ANSWER

              I added a new toggleCheckClasses function that adds / removes the right fa classes depending on the state of the checkbox. And I attached this function to the tree nodes in your treejs-ready / click handler.

              EDIT : I added the toggling of children elements classes

              $(document).ready(function() {
                  $("#SampleContainer").jstree({
                      "plugins": ["checkbox"],
                      core: {
                          "themes": {
                              "icons": false,
                              "responsive": true
                          }
                      }
                  });
                  $('#SampleContainer').on('ready.jstree click', function(e, data) {
                      $('a > i.jstree-checkbox')
                          .removeClass('jstree-icon jstree-checkbox') // removing jstree classes
                          .addClass('fa fa-square-o') // adding the fa non-checked checkbox class
                          .on('click', function() { // attaching the handler that toggles the checked / unchecked class
                              toggleCheckClasses($(this), $(this).hasClass('fa-square-o'));
                          });
                  });
              
                  function toggleCheckClasses(element, show) {
                      if (show) {
                          element.removeClass('fa-square-o');
                          element.addClass('fa-check-square-o');
                      } else {
                          element.removeClass('fa-check-square-o');
                          element.addClass('fa-square-o');
                      }
              
                      var children = element.parent().siblings(".jstree-children").find(".jstree-anchor .fa");
              
                      children.each(function() {
                          toggleCheckClasses($(this), show);
                      });
              
                  }
              
              });
              <link href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/themes/default/style.min.css" rel="stylesheet"/>
              <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet"/>
              
              <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
              <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.5/jstree.min.js"></script>
              <div id="SampleContainer">
              <ul> 
                <li>
                  Top 1
                  <ul>
                    <li>
                      Sub 1
                      <ul>
                        <li>
                          A
                        </li>
                        <li>
                          B
                        </li>
              
                      </ul>
                    </li>
                    <li>
                      Sub 2
                      <ul>
                        <li>
                          A
                        </li>
                        <li>
                          B
                        </li>
              
                      </ul>
                    </li>
                  </ul>
                </li>
              
              </ul>
              </div>

              0
              Ruwen Ruwen On 11 April 2022 at 14:19

              The interactions in the tree are not shown clean with the jquery css classes manipulation.

              I created a touch friendly jsTree with high-resolution icons

              I wrote an additional CSS File that overrides jsTree's style for checkboxes and carets with scalable flat font-awesome Icons (FontAwesome version: 4.7.0 FontAwesome v4).

              You can use the following CSS included after jsTree's CSS file and FontAwesome v4.

              Preview:

              enter image description here

              CSS:

              .jstree-icon.jstree-checkbox, .jstree-no-dots .jstree-closed>.jstree-ocl, .jstree-no-dots .jstree-open>.jstree-ocl {
                background-image: none;
                background-position: initial;
                color: #767676;
              
                display: inline-block;
                font: normal normal normal 14px/1 FontAwesome;
                font-size: inherit;
                text-rendering: auto;
                -webkit-font-smoothing: antialiased;
                -moz-osx-font-smoothing: grayscale;
              }
              
              .jstree-icon.jstree-checkbox:before {
                content: "\f096";
                font-size: 17px;
              }
              
              .jstree-default-large.jstree-checkbox-selection .jstree-clicked>.jstree-checkbox:before, .jstree-default-large .jstree-checked>.jstree-checkbox:before {
                content: "\f046";
                font-size: 17px;
                margin-left: 2px; /* checkedSquare icon is wider -> margin simulates same square position as unchecked */
              }
              
              .jstree-default-large .jstree-anchor>.jstree-undetermined:before{
                content: "\f147";
                font-size: 17px;
              }
              
              .jstree-default-large>.jstree-no-dots .jstree-closed>.jstree-ocl:before{
                content: "\f0da";
                line-height: 32px;
              }
              
              .jstree-default-large>.jstree-no-dots .jstree-open>.jstree-ocl:before{
                content: "\f0d7";
                line-height: 32px;
              }
              

              So there is no need to manipulate jsTree's DOM via javascript / jquery.

              The folder icon is set via the jsTree() Initialisation (fontAwesome's fa-folder-open. Ecerything colored with CSS.

              .jstree({
                  "types":   {
                      "default": {
                          "icon": "fa fa-folder-open treeFolderIcon",
                      }
                  },
                  "plugins": plugins,
                  "core":    {
                      "themes": {"variant": "large"},
                      }
                  }
              });
              

              Related Questions in JAVASCRIPT

              • Angular Show All When No Filter Is Supplied
              • Why does a function show up as not defined
              • I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
              • Set "More" "Less" font size
              • Using pagination on a table in AngularJS
              • How to sort these using Javascript or Jquery Most effectively
              • how to fill out the table with next values in array with one button
              • State with different subviews
              • Ajax jQuery firing multiple time display event for the same result
              • Getting and passing MVC Model data to AngularJS controller
              • Disable variable in eval
              • javascript nested loops waiting for user input
              • .hover() seems to overwrite .click()
              • How to sort a multi-dimensional array by the second array in descending order?
              • How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?

              Related Questions in JQUERY

              • How to sort these using Javascript or Jquery Most effectively
              • Ajax jQuery firing multiple time display event for the same result
              • .hover() seems to overwrite .click()
              • Check for numeric value with optional commas javascript
              • Extending Highmaps Side Effect
              • Array appending after each onclick and loop in javascript
              • how can i append part of a table based on how many tr it has?
              • Play multiple audio files in a slider
              • Remove added set of rows
              • Access property of an object of type [Model] in JQuery
              • AJAX PHP - Reload div after submit
              • proengsoft/laravel-jsvalidation ReferenceError: jQuery is not defined
              • when a checkbox is checked how to display a different hidden element using javascript
              • Get jquery error Uncaught RangeError: Maximum call stack size exceeded
              • Removing only the closest thead on table filtering

              Related Questions in HTML

              • Delay in loading Html Page(WebView) from assets folder in real android device
              • Why does a function show up as not defined
              • CSS Class is not applying to element (border width,color,and style attributes)
              • How to sort these using Javascript or Jquery Most effectively
              • how to fill out the table with next values in array with one button
              • Automatically closing tags in form input?
              • Positioning child at bottom of parent with scroll
              • Remove added set of rows
              • Website zoomed out on Android default browser
              • Twitter Bootstrap horizontal form elements on a line
              • http://sigmajs.org/ les mis tutorial - why are my canvases 0 height?
              • My navbar is not expanding after collapse
              • when a checkbox is checked how to display a different hidden element using javascript
              • Gaps Vertically Using Dividers
              • Svg containers not positioning properly

              Related Questions in JSTREE

              • jsTree can't select leafs
              • Create link in deepest node with jsTree to controller?
              • JQuery JsTree: jstree is not rendering properly in browser
              • Populate jstree parent nodes dynamically
              • Parent node check in jstree
              • Is there a ready solution to handle a jstree within a mCustomScrollbar?
              • jstree - one tree in different pages
              • jstree html and json
              • How to get the index of selected nodes in jstree
              • Collapse tree after checking all nodes with jsTree
              • Dynamic load of whole jstree
              • How to get parent and parent's parent id in jstree
              • changed.jstree event not working in jstree inside of class method
              • JSTree adding nodes to child nodes
              • Not able to see folder name in jstree. Only icon is shown

              Related Questions in JSTREE-SEARCH

              • jsTree asynchronous search - trigger load new nodes
              • jsTree ajax parameter not even sending requests
              • JsTree with custom xml or json structure
              • jsTree search plugin and special chars
              • jstree lazy load specific nodes and select those
              • Angular jstree search plugin
              • JSTree font awesome check Box
              • jstree : Uncaught TypeError: Cannot read property 'children' of undefined
              • Jstree: I can't reset all the checkboxes to uncheck by default when I reload my tree
              • To show depth level on each node jstree
              • How to know if all checkbox of jstree is checked or not
              • JS Tree - Select parent node when all the child nodes are selected
              • Fetching selected checkboxes from jstree
              • jsTree AJAX search with some node childs?
              • JStree Async Search

              Trending Questions

              • UIImageView Frame Doesn't Reflect Constraints
              • Is it possible to use adb commands to click on a view by finding its ID?
              • How to create a new web character symbol recognizable by html/javascript?
              • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
              • Heap Gives Page Fault
              • Connect ffmpeg to Visual Studio 2008
              • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
              • How to avoid default initialization of objects in std::vector?
              • second argument of the command line arguments in a format other than char** argv or char* argv[]
              • How to improve efficiency of algorithm which generates next lexicographic permutation?
              • Navigating to the another actvity app getting crash in android
              • How to read the particular message format in android and store in sqlite database?
              • Resetting inventory status after order is cancelled
              • Efficiently compute powers of X in SSE/AVX
              • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

              Popular # Hahtags

              javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

              Popular Questions

              • How do I undo the most recent local commits in Git?
              • How can I remove a specific item from an array in JavaScript?
              • How do I delete a Git branch locally and remotely?
              • Find all files containing a specific text (string) on Linux?
              • How do I revert a Git repository to a previous commit?
              • How do I create an HTML button that acts like a link?
              • How do I check out a remote Git branch?
              • How do I force "git pull" to overwrite local files?
              • How do I list all files of a directory?
              • How to check whether a string contains a substring in JavaScript?
              • How do I redirect to another webpage?
              • How can I iterate over rows in a Pandas DataFrame?
              • How do I convert a String to an int in Java?
              • Does Python have a string 'contains' substring method?
              • How do I check if a string contains a specific word?
              .

              Copyright © 2021 Jogjafile Inc.

              • Disclaimer
              • Privacy
              • TOS
              • Homegardensmart
              • Math
              • Aftereffectstemplates