score:1

Accepted answer

Instead of using

if (d.children === null){
    alert(d.id);
}

Use

if (!d.children){
    alert(d.id);
}

This is because d.children would be undefined but you were checking for null. Since undefined and null equate to false !d.children check will succeed.


Related Query