Question

Using jQuery, I would like to change the cursor on page when any key is pressed (for example Ctrl). Simple task, however I can not get make it work... This was my first idea, obviously - does not work:

$(document).on('keydown',function(){
  $(document).css('cursor','wait');
});

Any idea what is wrong?

Was it helpful?

Solution

Think what you want is something like this:

$('body').css('cursor','wait');

You can't apply CSS to the document. Also if you wanted to only apply this css to the CTRL key press you could do:

$(document).on('keydown', function (event) {
    if (event.ctrlKey) {
        $('body').css('cursor', 'wait');
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top