rekoDolph
rekoDolph

Reputation: 823

How to select all unselected nodes ? d3/js

Really simple question but how do you select all unselected nodes ? I have nodes classed as .selectedNode, how do I select the inverse (everything else).

d3.selectAll(".selectedNode")

What I want to do is apply a class to all unselected nodes to hide the, : visibility:hidden

Upvotes: 0

Views: 427

Answers (2)

Ben Tayaa
Ben Tayaa

Reputation: 476

Try to use the selector ":not" :

3D JS Code :

d3.selectAll("div:not(.selectedNode)").style("display", "none");

Html

<div class="selectedNode"> <h4>Selected Node 1<h4> </div>
<div class="selectedNode"> <h4>Selected Node 2<h4> </div>
<!-- this div will be hide -->
<div class="unSelectedNode"> <h4> Unelected Node 3<h4> </div>
<div class="selectedNode"> <h4>Selected Node 4<h4> </div>
<div class="selectedNode"> <h4>Selected Node 5<h4> </div>

You can try it right now : http://jsfiddle.net/Bentayaa/dcavpdbr/

I hope that will help.

Best regards

Upvotes: 2

rekoDolph
rekoDolph

Reputation: 823

Here is how I solved it :)

nodes.classed("hidden", function (d)
        {
            return d.selected ? false : true;
        });

Basically says if its selected dont give it the hidden class but if it isnt selected give it the hidden class :)

Upvotes: 2

Related Questions