• 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

              • Using Puppeteer to scrape a public API only when the data changes
              • inline SVG text (js)
              • An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
              • Storing the preferred font-size in localStorage
              • Simple movie API request not showing up in the console log
              • Authenticate Flask rest API
              • Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
              • How to request administrator rights?
              • mp4 embedded videos within github pages website not loading
              • Scrimba tutorial was working, suddenly stopped even trying the default
              • In Datatables, start value resets to 0, when column sorting
              • How do I link two models in mongoose?
              • parameter values only being sent to certain columns in google sheet?
              • Run main several times of wasm in browser
              • Variable inside a Variable, not updating

              Related Questions in JQUERY

              • In Datatables, start value resets to 0, when column sorting
              • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
              • window.location.href redirects but is causing problems on the webpage
              • Using JQuery Date Slider
              • Storing selected language in localStorage
              • How to stop other divs from still showing when i click a different button?
              • Check multiple values with jQuery
              • Bootstrap component does not want to render in Datatables function
              • put white spaces when entering an amount moneytype symfony
              • Trouble accessing custom header in AJAX response using jQuery in Fiware Keyrock
              • I just cant make it work, HTML, JS and Firebase error
              • Didn't declared variable still not getting any error in JavaScript
              • Move element horizontally while scrolling vertically in pure JavaScript
              • allow multi carousel in same page
              • Embedded TikTok posts / thumbnail styling issue

              Related Questions in HTML

              • How to store a date/time in sqlite (or something similar to a date)
              • How to use custom font during html to pdf conversion?
              • Storing the preferred font-size in localStorage
              • mp4 embedded videos within github pages website not loading
              • Scrimba tutorial was working, suddenly stopped even trying the default
              • Is there any way to glow this bulb image like a real light bulb
              • With non-graphical maps in Leaflet, zoomDelta doesn't work
              • What can I do to improve my coding on both html and css
              • Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
              • Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
              • Displaying a Movie List on a Website Using Jinja2 and Bootstrap
              • How to redirect to thank you page after submitting a Google form embedded into a Google Site?
              • Storing selected language in localStorage
              • Fences (parenthesis, braces) in HTML and MathML
              • Understanding Scroll Anchoring Behavoir

              Related Questions in JSTREE

              • ASP.NET Core 8.0 MVC : .jsTree hierarchy menu from SQL Server database
              • Using front-end timout with jsTree
              • The jsTree plugin does not allow the user to select text using mouse
              • How to filter dataframe based on tree input
              • How to programmatically invoke contextmenu action in jstree?
              • How to modify contextmenu in jstree to get rid of unwanted space and align material icon with the text?
              • jsTreeR bug and how to use it as an input in shiny
              • Shinytree render gone if the panel is being collapsed by opening another panel
              • jstree add toggle Node used json fomat
              • MenuItem doesn't always show the tree if there are multiple menuItems
              • State is cleared after refreshing
              • Jstree adjust vertical gap between nodes
              • How to return expanded jsTree where tree is generated recursively with chrome.bookmarks.getSubTree
              • JSTree not picking up custom leaf node icon
              • jsTree - How set selected node after page refreshed?

              Related Questions in JSTREE-SEARCH

              • JStree Search doesn't show up
              • jsTree ajax parameter not even sending requests
              • Show only matched node(s) in jsTree
              • How to know if all checkbox of jstree is checked or not
              • Using Checkbox, When all child nodes are deleted, parent node also getting deleted in JStree
              • Create Functionality in Context Menu of jsTree not working
              • JsTree with custom xml or json structure
              • jsTree search query for child nodes only
              • JSTree font awesome check Box
              • jstree with ajax search and massload plugin
              • how to deselect all nodes in JSTree
              • jstree lazy load specific nodes and select those
              • Angular jstree search plugin
              • show_only_matches not working for jstree's search plugin
              • To show depth level on each node jstree

              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 node.js arrays c asp.net json

              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