Answers for "on spacebar press javascript"

1

execute JS code after pressing space bar

document.body.onkeyup = function(e){
    if(e.keyCode == 32){
        //your code
    }
}
Posted by: Guest on June-19-2020
0

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();
}
Posted by: Guest on May-30-2021
0

on spacebar press javascript

document.body.onkeyup = function(e){
    if(e.key == ' '){
        //your code
    }
}
Posted by: Guest on July-31-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language