function keypressCheck() {
var keyID = event.keyCode;
//space pressed
if (keyID == 32) {
anotherFunction();
}
}
I want anotherFunction()
to run when the space bar is pressed without the default action of the page scrolling to happen. is there any way to do this?
It should work. Just to make sure, try this:
function keypressCheck(e) {
var e = window.event||e; // Handle browser compatibility
var keyID = e.keyCode;
//space pressed
if (keyID == 32) {
e.preventDefault(); // Prevent the default action
anotherFunction();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With