title: Detecting keypress in D3.js
body: <p>I have read many posts and answers, but they all seem to be out of date.</p>
  
  <p>My goal is to be able to "tab" through text and run a function on enter and/or spacebar. I have tried <code>keyCode</code>, <code>charCode</code>, <code>key</code>, <code>which</code>, <code>keypress</code>, <code>keyup</code>, <code>keydown</code> etc...</p>
  
  <p>I have a text node that I can tab through using:</p>
  
  <pre><code>.attr('role', 'button')
  .attr('tabindex', '0')
  .attr('focusable', 'true')
  .on('click', sel)
  .on('keypress', function(){if(key == 13 || key == 32){return sel}}) 
  </code></pre>
  
  <p>The on click is perfect and the tab works, just the function is not called when the space and enter are used.</p>
  
  <p>any help is appreciated.</p>