How to change cursor to waiting state in JavaScript/jQuery ?

Given an HTML document and the task is to get the waiting state cursor when mouse moves over an element. Here we are going to achieve that by cursor property which allows to do operation on the cursor. We are going to do that with the help of JavaScript.

Approach:

  • Use the cursor property.
  • Set its value to progress when waiting cursor is needed.
  • Set its value to default when standard cursor is needed.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>  
<html>  
  
<head
    <title
        How to change cursor to waiting
        in JavaScript/jQuery ?
    </title>
      
    <script src=
    </script>
      
    <style>
        #div {
            height: 100px;
            width: 200px;
            background: green;
            color: white;
            margin: 0 auto;
        }
    </style>
</head
      
<body style = "text-align:center;">  
      
    <h1 id = "h1" style = "color:green;" >  
        GeeksforGeeks
    </h1>
      
    <p id = "GFG_UP" style
        "font-size: 15px; font-weight: bold;">
    </p>
      
    <div id = "div">
        Hover over it
    </div>
      
    <script>
        var el_up = document.getElementById("GFG_UP");
        var heading = document.getElementById("h1");
        var div = document.getElementById("div");
        el_up.innerHTML = "Hover over the element "
                    + "to see the waiting cursor.";
          
        $("#div").hover(function() { 
            $(this).css("cursor", "progress"); 
        }, function() { 
            $(this).css("cursor", "default"); 
        });  
    </script
</body>
  
</html>

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>  
<html>  
  
<head
    <title
        How to change cursor to waiting
        in JavaScript/jQuery ?
    </title>
      
    <script src=
    </script>
      
    <style>
        #div {
            height: 100px;
            width: 200px;
            background: green;
            color: white;
            margin: 0 auto;
        }
        .cursor {
               cursor: progress;
           }
    </style>
</head
      
<body style = "text-align:center;">  
      
    <h1 id = "h1" style = "color:green;" >  
        GeeksforGeeks
    </h1>
      
    <p id = "GFG_UP" style
        "font-size: 15px; font-weight: bold;">
    </p>
      
    <div id = "div">
        Hover over it
    </div>
      
    <script>
        var el_up = document.getElementById("GFG_UP");
        var heading = document.getElementById("h1");
        var div = document.getElementById("div");
        el_up.innerHTML = "Hover over the element "
                    + "to see the waiting cursor.";
          
        $("#div").hover(function() { 
            $(this).addClass('cursor'); 
        }, function() { 
            $(this).removeClass('cursor');
        });  
    </script
</body>  
  
</html>

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.