keydown + keyup events for specific keys
I'm trying to make the background color change when certain keys are held down. For example, when the 'r' key is being held down, the background should be red. When the 'r' key is not being pressed anymore, the background should default to white. $(document).ready(function () { $('body').keydown(function(e){ if(e.keyCode == 114){ $(this).css({'background':'red'}); } if(e.keyCode == 121){ $(this).css({'background':'yellow'}); } }); $('body').keypress(function(e){ if(e.keyCode == 114){ $(this).css({'background':'red'}); } if(e.keyCode == 121){ $(this).css({'background':'yellow'}); } }); $('body'