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:
<!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
filter_none
Output:

Example 2:
<!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
filter_none
Output:

Recommended Posts:
- How to change cursor style using jQuery ?
- CSS | Animation to Change the Hover State of a Button/Image
- How to call a function automatically after waiting for some time using jQuery?
- p5.js | cursor() Function
- CSS | cursor property
- JavaScript | Cursor property
- Hide the cursor in a webpage using CSS and JavaScript
- HTML | DOM Style cursor Property
- How to set cursor style to pointer for links without href ?
- How to make the cursor to hand when a user hovers over a list item using CSS?
- ReactJS | State in React
- ReactJS | State vs props
- ReactJS | Implementing State & Lifecycle
- CSS | animation-play-state Property
- How to change the height of br tag?
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.



