How to color node tree in javascript

I have a treeview and texbox that allows the user to search for nodes inside the treeview.

i already wrote a JS function that determines if node view exists in the tree.
 I want the color of the node that the user was looking for. How can i do this?

+3
source share
2 answers

Use CSS and change the class name in Javascript. So say your nodes are div. When you find node, in Javascript you will do something like:

divFoundNode.className = "selected";

Then make sure your CSS has the selected class with the background color set. It will look something like this:

.selected {background-color:red;} /* whatever your selected color is here */

CSS, node, - :

divFoundNode.style.backgroundColor = "red";

, , , . node. . (, ), Javascript div . , - :

var divLastFoundNode; //global variable

function treeView_SelectNode(divFoundNode)
{
     divLastFoundNode.className = "";
     divFoundNode.className = "selected";
     divLastFoundNode = divFoundNode;
}

JQuery . . :

$("div.node").removeClass("selected");
$(divFoundNode).addClass("selected");
+2

- , ?

document.getElementById("foundnodeid").style.color="#abcdef";

, , :

document.getElementById("foundnodeid").style.class="classwithdifferentcolor";

0

Source: https://habr.com/ru/post/1745976/


All Articles