I've got an interactive graph built with d3, and I capture the backspace key to remove elements from the graph. However, I also have a text box on the page, and I'd like to be able to use backspace while typing. Is there a way to allow the backspace through in the text box, or to only capture it in the main svg of the graph?
My code:
var BACKSPACE_KEY = 8;
d3.select(window).on("keydown", function() {
switch (d3.event.keyCode) {
case BACKSPACE_KEY:
// So that the browser doesn't go back
d3.event.preventDefault();
// Clean up my graph with the backspace key
// ...
}
})
A fiddle demonstrating the problem: https://jsfiddle.net/5pamrn3m/