I want to simulate a Keypress event using the Javascript Console. I see lots of answers using an input element. I don't want to use an input element. I just want to paste some code into the Javascript console and have a keypress event simulated(specifically the back space button).
Answers using jQuery are welcome.
jQuery has a
.keypress
method accepting no arguments that simulates a keypress.Will trigger a keypress on
#target
If you'd like to also select which key was pressed, you can use
.trigger
. This example is from the docs:The key code 8 is the key code for backspace in JavaScript.
Let me know how that works for you :)