I want to change the color of a
when it is clicked by a mouse or while pressing the enter key.<
Use a combination of keypress/keyup to toggle the color:
$("button").keydown(function(e) {
// Sets the color when the key is down...
if(e.which === 13) {
$(this).css("background-color", "red");
}
});
$("button").keyup(function() {
// Removes the color when any key is lifted...
$(this).css("background-color", "");
});