remove image by pressing delete in browser

61 views Asked by At

how can i detect that delete key is pressed i am working with lot of images generated dynamically with php. now i want to provide a functionality so that when delete key is pressed that images is removed from page but the problem is that how can i detect that a delete key is pressed please point me in the right direction such as

$('img').delete(function(){

    // delete code
});

is this possible using jquery, javascript or php.

2

There are 2 answers

0
Dion On BEST ANSWER

Take a look at this: https://api.jquery.com/keydown/ Inside the function you can remove the image.

0
Cjmarkham On

You can use onkeydown to detect a key press and then check if it is the delete key.

You can check for key codes here