Code for triggering an event when a user presses a key?

Kmandapalli
Posted by Kmandapalli under jQuery category on | Points: 40 | Views : 511
var jq4u = 'jquery';
for (n = 0; n & lt; = 5; n++) {
$('#' + id).append('<div class=&quot;bigcolordiv key-' + jq4u[n] + '&quot; style=&quot;background-color:blue;&quot;>' + jq4u[n] + '</div>');
}

$(W).bind('keydown', function (key) {
//jquery, 74, 81, 85, 69, 82, 89
var keycode;
if (key == null) {
keycode = event.keyCode;
} else {
keycode = key.keyCode;
}
$('#' + id + ' .key-' + String.fromCharCode(keycode).toLowerCase()).toggleClass('orangebg');
});

Comments or Responses

Login to post response