Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:57:04+00:00 2026-05-15T14:57:04+00:00

Here’s my situation: using PHP and MySQL as my backend, jQuery and jsTree for

  • 0

Here’s my situation: using PHP and MySQL as my backend, jQuery and jsTree for my front end.

My tree is on the left, and clicking on a node will trigger certain information to be loaded in a box floated to the right of the tree. They can add/edit/remove nodes in this tree with this behavior (no page reload, all Ajax).

Currently, I can successfully add a node to the tree. I take user input for the new node, and if everything passes validation (client-side first, server-side second), a new “node” is added to my MySQL database, and then I update the jsTree on the fly with some Javascript by adding a new node to it’s parent (on initial page load, PHP correctly builds an HTML tree with unordered lists and list items).

My simple question: how do I add a new node to the jsTree with an “ID” attribute for the list item (“LI”)?

For reference, here’s what my HTML tree looks like. This is handed to jsTree and it’s HTML_DATA plugin:

<ul>
    <li class="plant" id="plant_3"><a href="javascript:void();">Plant Three</a>
     </li>
    <li class="plant" id="plant_1"><a href="javascript:void();">Plant One</a>
  <ul>
          <li class="area" id="area_2"><a href="javascript:void();">Area Two</a>
       </li>
          <li class="area" id="area_1"><a href="javascript:void();">Area One</a>
    <ul>
            <li class="building" id="building_1"><a href="javascript:void();">Building One</a>
      <ul>
              <li class="floor" id="floor_2"><a href="javascript:void();">1st Floor</a>
           </li>
              <li class="floor" id="floor_3"><a href="javascript:void();">2nd Floor</a>
           </li>
              <li class="floor" id="floor_1"><a href="javascript:void();">Ground Floor</a>
           </li>
          </ul>
         </li>
        </ul>
       </li>
      </ul>
     </li>
</ul>

My clicking actions are keyed on the unique ID’s that each node has (“plant_1”, “area_3”, etc.) Currently, when I add a jsTree node, I do it this way (through the CRRM plugin):

$("#my_tree").jstree("create", null, false, name, {attr : "id=plant_"+id}, true);

#my_tree is initialized with this:

$("#my_tree").jstree({
 "ui" : {
     "select_limit" : 1,
     "selected_parent_close" : "select_parent"
 },
 "html_data" : {
     "ajax" : {
  "url" : "file.php?action=get_my_tree",
  "data" : function (n) {
      return {
   id : n.attr ? n.attr("id"): 0
   };
  }
     }
 },
 "core" : {
     "animation" : 0
 },
 "plugins": [ "ui", "themes", "html_data", "hotkeys", "crrm"]
    });

Any ideas? The CRRM plugin documentation mentions a third parameter (in my code above, its the “{attr : “id=plant_”+id}”) that defines ‘attr’ data in object form.

An ideal solution would be the proper object to pass to jsTree+CRRM, but I’d look for even a hacked solution where an additional line of Javascript after my “create” line, where I “manually” add an ID to the newly inserted LI item.

For reference, here’s the HTML that jsTree inserts with my “create” line above:

<li class="jstree-leaf"><ins class="jstree-icon">&nbsp;</ins><a href="#"><ins class="jstree-icon">&nbsp;</ins>New Node!</a></li>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:57:05+00:00Added an answer on May 15, 2026 at 2:57 pm

    So, the problem with this line:

    $("#my_tree").jstree("create", null, false, name, {
        attr : "id=plant_" + id
    }, true);
    

    Is that the Javascript object’s attr is also an object. The correct line is as follows:

    $("#my_tree").jstree("create", null, false, name, {
        attr : {
            id: 'plant_' + id
        },
        data: name
    }, true);
    

    So you can determine several attributes to give your new leaf. The “id” attribute is actually given to the LI (list item), which is precisely what I needed.

    The jsTree documentation does mention that the attributes should be JS objects themselves, but I’m not overly familiar with a lot of the Javascript syntax, including objects.

    Just for posterity, here’s what is added to the jsTree’s HTML:

    <li id="plant_x" class="jstree-leaf">
        <ins class="jstree-icon">&nbsp;</ins>
        <a href="#">
            <ins class="jstree-icon">&nbsp;</ins>
            New Node!
        </a>
    </li>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.