Hi Guys,
I want to bind the keypress event handler when i click the div layer as given in the above demo. The feature is to use the delete key to remove the selected layer.
But when i hit the delete key, the keypress handler doesn’t fire. Please suggest.
Remove ‘
()‘:You are adding
undefinedas handler:$this.on("keypress", keyAction())is equal to$this.on("keypress", undefined)in your case, askeyActionfunction does not return anything.Also your
divmust be focusable, in order to receive keyboard events. For that reason you need to addtabindexon it:Then in
selectActionfocus your div to receive keypress event:This is the DEMO
For more information about adding
keyboard events on static elements such asdiv, look at here: