jstree create_node with li_attr

277 views Asked by At

i am using jstree and am already adding new nodes with the create_node function. But can anyone tell me how to add "li_attr" data while using the create_node function?

Thanks in advance

.jstree('create_node', $(parent_node), eval(new_node_text), position, false, false);
1

There are 1 answers

1
Shubham Raturi On BEST ANSWER

Hope This helps you. You can modify the li_attr property to include any other attributes or values that you need for your use case.

// Define the new node text and its attributes
var new_node_text = {
  "text": "New Node",
  "li_attr": {
    "data-attribute1": "value1",
    "data-attribute2": "value2"
  }
};

// Create the new node and add it to the parent node
$("#jstree").jstree("create_node", parent_node, new_node_text, "last", function(node) {
  // Callback function called after the node has been created
  // Here you can perform any additional actions on the new node
});