I'm trying to get text within a span element to change depending on the key pressed using the keydown function in Jquery.
The script runs fine until it comes to all my if statements.
A sample of my script:
$(document).ready(pressed);
function pressed(){
$('html').keydown(function (e) {
var a = 65;var b = 66;var c = 67;
if (e.keyCode == a){
$('span').text('a');
console.log('Key Pressed: a');
}else if(e.keyCode == b){
$('span').text('b');
console.log('Key Pressed: b');
}else if(e.keyCode == c){
$('span').text('c');
console.log('Key Pressed: c');
}
});
}
I have 2 different console logs that should get reported when a key is pressed. One when any key is pressed and one when a specific key gets pressed (currently only on a, b and c).
Can someone please tell me what I have done wrong and why it isn't functioning?
e.whichrather thane.keyCode