title: Can I call indexOf within a D3 selection?
body: <p>I am making a bar graph using D3 which uses an array of numbers <code>dataset[]</code> to generate and set the height of the bars.</p>
  
  <p>I have a portion of code which generates a tooltip upon mouseover of a bar element.</p>
  
  <pre><code>d3.select("#tooltip")
      .style("left", xPosition + "px")
      .style("top", yPosition + "px")                     
      .select("#share-value")
      .text(d)
      .select("#month-now")
      .text(dataset.indexOf(d));
  console.log(dataset.indexOf(d));
  </code></pre>
  
  <p><code>text(d)</code> displays correctly, which is the value of <code>dataset[d]</code>. However, I would also like to display the index of the element <code>d</code> in <code>dataset</code>. <code>console.log(dataset.indexOf(d))</code> logs the index correctly but the index is not being displayed in the tooltip. Why is this so?</p>
  
  <p>Edit: I have also tried</p>
  
  <pre><code>.text(function (d, i) {
          return i;
      });
  </code></pre>
  
  <p>according to <a href="https://github.com/mbostock/d3/wiki/Selections" rel="nofollow">D3 Selections</a>, but it still does not seem to return the index of the current datum.</p>