title: Get id of dragged element in d3.js
body: <p>I am probably having some kind of brain damage atm because something like <strong>this should be trivial</strong>.</p>
  <p>I got a bunch of SVG circles rendered manually (via React). I am then attaching d3 drag behavior to all of them. The drag behavior is applied, and the drag function is being executed, but when I drag one of these circles I am not able to respond accordingly because I do not know which one of them was moved. <strong>Where can I get the ID of dragged element</strong>?</p>
  <p>I have checked a few other questions and found just some crazy filter solution... that cannot be it.</p>
  <p>I have also peeked at <a href="https://github.com/d3/d3-drag#drag_on" rel="nofollow noreferrer">docs</a> and found the <code>subject</code> property.. however that one is null everywhere I tried it.</p>
  <p>My code:</p>
  <pre><code>componentWillUpdate() {
    let nodes = d3.selectAll(&quot;circle&quot;);
  
    const dragFn = (d,i) =&gt; {
      d3.event.sourceEvent.stopPropagation();
      this.props.onNodeDrag(I_NEED_AN_ID_HERE);
    }
  
    const dragBehavior = d3.behavior.drag();
    dragBehavior.on('drag', dragFn);
    dragBehavior.on('dragstart', () =&gt; {
      d3.event.sourceEvent.stopPropagation();
    });
  
    nodes.call(dragBehavior);
  }
  </code></pre>