How to add click event on d3.js child of collapsible tree?

235
January 29, 2018, at 9:12 PM

I'm using d3.js for collapsible tree structure from here
Now my goal is to add a click event on the final child (i.e) Son of A or Daughter of A
For example I need to create an alert box on clicking the childless node.

I tried to add a condition within the click function, but it works only on my second click and I don't get it why the alert box is not getting up on my first click.

Could some one explain me why is it so? and what is the right way to do it?

MY CLICK FUNCTION

function click(d) {
if (d.children) {
    d._children = d.children;
    d.children = null;
  } else {
    d.children = d._children;
    d._children = null;
    if (d.children === null){
        alert(d.id);
    }
  }
update(d);
}
Rent Charter Buses Company
READ ALSO
PHP JSON_ENCODE Process Gets Aborted by ESCAPE key

PHP JSON_ENCODE Process Gets Aborted by ESCAPE key

My web page uses bootstrap and jquery, and during a rather long page load, which reads some PHP session variables with JSON_ENCODE, pressing the ESCAPE key seems to stop the process, aborting the read, and causing the page load to fail

266
Styling <input type=“file”> CSS error [duplicate]

Styling <input type=“file”> CSS error [duplicate]

This question already has an answer here:

285
Wrap jQuery plugins method in angularJS

Wrap jQuery plugins method in angularJS

my project has several jQuery plugins and I need to wrap them inside angularJSI did some research and I found how to make a custom directive for initialization

273
Javascript change text on label with for

Javascript change text on label with for

Hi i need change text via Javacript in this labelsLabels have not class or id, only atribute for

185