Reputation: 787
I have made divs in my HTML that I use to draw bars with CSS. Now I want the to values change when the user presses the down arrow key.
This is my JavaScript:
var changeIdValue = function(id, value) {
document.getElementById(id).style.height = value;
};
window.addEventlistener("onkeydown", function(e){
if(e.keyCode == 40){
changeIdValue("balklongwaarde", "60px");
});
}
I don't understand why this is not working.
Upvotes: 0
Views: 895
Reputation: 2969
I know this has been answered already, but if you want to follow your original idea, here's the correct code (because Mritunjay's answer only works for one usage per page).
var changeIdValue = function (id, value) {
document.getElementById(id).style.height = value;
};
window.addEventListener('keydown', function (e) {
if (e.keyCode === 40) {
changeIdValue('balklongwaarde', '60px');
}
});
Upvotes: 2
Reputation: 25892
You can say something like this
window.onkeydown = function(e){
if(e.keyCode == 40)
changeIdValue("balklongwaard", "60px");
};
Upvotes: 0