Writing A Function for Tooltips in D3
<p>I have a force directed graph and I'm trying to write a function to display the names of the inbound and outbound nodes in a tooltip. I'm okay with the tooltip part, but I'm new to js and can't seem to get the function right. Here's what I'm trying:</p>

<pre><code>var tip = d3.tip()
  .attr('class', 'd3-tip')
  .offset([-10, 0])
  .html(function(d) {
   names = ""
links.forEach (function(links)
  { if (links.source == d.name) {names.append (links.source)}}
  { if (links.target == d.name) {names.append (links.target)}}
  {return names}
  )});
</code></pre>

<p>I want to return the names string as html. I have to pass through the source and target because some nodes are only targets.</p>