Is there a way to add a Tooltip to a JSTree node? I would like to display extra information when the user hovers over an element.
I'm pretty dense when it comes to JQuery so there may be an obvious answer to this.
Edit:
Thanks to zzzz below, I am able to get a simple hover box to pop up. I still cannot apply a fancy JQuery Tooltip to it despite putting the tree's div
within a fieldset
as the instructions within the Tooltip page would suggest.
Adding a tool tip to jstree is very simple . Before writing down the steps let me explain what I will be doing
Prerequisites: you should use jquery library and other dependencies. So in your head tag it should look something like this
The above code will get the jquery library and the required css. Also it will create required style for the tool tip
So now for the steps to be taken on the Jstree. note that iam writing this answer for the latest verison of jstree 3.0.2
We will need to catch the 'hover_node.jstree'
This is all what you have to do and the jquery will take care of the rest to show the tooltip
Logic which is behind this is that jquery automatically checks if there is tittle attribute associated with any node(i.e element) and then displays the tooltip if there's any title associated. So all what we are doing is just adding the title to node dynamically . This gives you flexibility to add custom tooltip on each node depending on your data for each node or you can also hardcode if it is a fixed one.
For more customizing and styling you can refer Jquery Tooltip
isnt it just about adding a title attribute to your node in the tree that is hovered on?? nothing fancy..
Use the "a_attr" or "li_attr" to add a title, depending on which element you want the title to be on, as documented here: https://www.jstree.com/docs/json/
If using the "create_node" function, then do it like this:
The above will show a tooltip in the browser. If you want to use a custom tooltip (e.g. Bootstrap), then you can simply call $(".show_tooltip").tooltip();
I create my jstree dynamically using the
create_node
function:And then I define the
.show_tooltip
class as tooltip:$(".show_tooltip").tooltip();
Do create tooltip bind the values with jstree .bind("hover_node.jstree", function(e, data){