javascript on spacebar press code example
Example 1: execute JS code after pressing space bar
document.body.onkeyup = function(e){
if(e.keyCode == 32){
}
}
Example 2: javascript on spacebar press
var hits = 0;
var hitElement = document.querySelector('.hits');
document.body.onkeyup = function (e) {
if (e.keyCode == 32) {
addHit();
}
}
var addHit = function () {
hits++;
renderHits();
}
var renderHits = function () {
hitElement.innerHTML = hits;
}
var resetHits = function () {
hits = 0;
renderHits();
}