score:7

Accepted answer

If you always PREpend any link (i.e. add the links to the container before any of the nodes), there will never be a link overlapping a node. You do that with insert(), which will prepend as long as you specify a selector matching the nodes you want to keep in on top:

forceContainer.selectAll('.node').data(force.nodes())
forceContainer.enter()
  .append('div')
  .attr('class', 'node')

forceContainer.selectAll('.link').data(force.links())
forceContainer.enter()
  .insert('div', '.node') // Inserts link before any of the existing nodes

Related Query

More Query from same tag