Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
How to stop setInterval Call in JavaScript ?
Next article icon

How to set the cursor to wait in JavaScript ?

Last Updated : 18 Aug, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

In JavaScript, we could easily set the cursor to wait. In this article, we will see how we are going to do this. Actually, it's quite an easy task, there is a CSS cursor property and it has some values and one of the values is wait. We will use the [cursor: wait] property of CSS and control its behavior using JavaScript. 

Setting the cursor to the wait could be useful in many cases, for example, if we click on the complete payment button in some payment transaction page then we should make the cursor to the wait just after the button get clicked, to prevent the unwanted click on anywhere on the page until the transaction is completed.

Example 1: In this example, we will create a button, when the button gets clicked then the cursor will be waiting. For this, we will use the addEventListener() function of JavaScript. With the help of this, we could control the behavior of events like click, hover, etc.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <Style>         * {             margin: 0px;             padding: 0px;             box-sizing: border-box;         }                  .box {             display: flex;             justify-content: center;             align-items: center;             height: 100vh;             background-color: rgb(36, 36, 36);         }                  #btn {             height: 50px;             width: 100px;             border-radius: 10px;             border: none;             outline: none;             background-color: rgb(2, 151, 2);             font-family: Impact, Haettenschweiler,                  'Arial Narrow Bold', sans-serif;             font-size: 1.1rem;         }     </Style> </head>  <body>     <div class="box">         <button id="btn">Click me</button>     </div>      <script>         document.getElementById("btn")             .addEventListener("click", function() {                 document.body.style.cursor = "wait";                  document.getElementById("btn")                     .style.backgroundColor = "gray";                  document.getElementById("btn")                     .style.cursor = "wait";             });     </script> </body>  </html> 

Output:

Example 2: For this example, we will use the same JavaScript's addEventListener() method, use the hover event, and specify where the cursor should go to wait. In this case, we have created two containers, The cursor will work fine in the first container but on the second one, the cursor will go to the wait.

HTML
<!DOCTYPE html> <html lang="en">  <head>     <meta charset="UTF-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <meta name="viewport" content=         "width=device-width, initial-scale=1.0">      <Style>         body {             margin: 0px;             padding: 0px;             box-sizing: border-box;         }                  .box {             display: flex;             justify-content: center;             align-items: center;             height: 100vh;             background-color: rgb(36, 36, 36);         }                  #box1 {             height: 100px;             width: 100px;             border-radius: 50%;             background-color: Green;         }                  #box2 {             height: 100px;             width: 100px;             border-radius: 50%;             background-color: rgb(102, 11, 3);             margin: 5px;             cursor: wait;         }     </Style> </head>  <body>     <div class="box">         <div id="box1"></div>         <div id="box2"></div>     </div>      <script>         document.getElementById("box2")             .addEventListener("hover", function() {                 document.getElementById("box2")                     .style.cursor = "wait";             });     </script> </body>  </html> 

Output: 


Next Article
How to stop setInterval Call in JavaScript ?
author
iamgaurav
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript-Questions
  • JavaScript-Events

Similar Reads

  • 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 the mouse moves over an element. Here we are going to achieve that by cursor property which allows doing an operation on the cursor. We are going to do that with the help of JavaScript.Approach:   Use the cursor property.Set
    3 min read
  • How to Wait n Seconds in JavaScript?
    Here are the various methods to wait n seconds in JavaScript 1. Using setTimeout() FunctionsetTimeout() is an asynchronous function in JavaScript that allows you to run code after a specific amount of time has passed. Since setTimeout() is a method of the window object, you can technically write it
    3 min read
  • How to wait for multiple Promises in JavaScript ?
    Waiting for multiple promises in JavaScript involves using Promise.all() or Promise.allSettled() methods. These methods accept an array of promises as input. Promise.all() waits for all promises to either resolve or reject, providing a single promise that resolves with an array of results or rejects
    3 min read
  • How to stop setInterval Call in JavaScript ?
    In JavaScript, the setInterval() function is used to repeatedly execute a specified function at a fixed interval. However, there may be scenarios where we need to stop the execution of setInterval() calls dynamically. Stopping a setInterval() call in JavaScript is essential to prevent ongoing repeti
    2 min read
  • How to Set Time Delay in JavaScript?
    Delaying the execution of code is a fundamental technique that is commonly used in JavaScript for tasks like animations, API polling, or managing time intervals between actions. JavaScript provides several built-in methods to set time delays: setTimeout() and setInterval(). We can set time delay in
    2 min read
  • How to access the Value of a Promise in JavaScript
    In this article, we will see how to access the value of Promise in JavaScript. The Promise is a feature of ES6 introduced in 2015. The concept of Promises is generally used when we want to work asynchronously. The value of a Promise can be accessed in JavaScript using the following methods. Table of
    2 min read
  • How to Make JavaScript Sleep or Wait?
    In JavaScript, there is no built-in sleep function like in some other programming languages. However, you can create a delay or pause in code execution by using asynchronous methods. We can use setTimeout() or Promise along with async/await to achieve this functionality for more readable code. 1. Us
    2 min read
  • How to Execute setInterval Function without Delay for the First Time in JavaScript?
    When working with JavaScript, the setInterval function is a powerful tool for executing a block of code repeatedly at specified intervals. The setInterval() method always invokes the function after the delay for the first time. Approach 1: Calling the function once before executing setInterval:Invok
    2 min read
  • How to set Cursor Style to Pointer for Links Without href?
    Setting the cursor style to a pointer for links without an href attribute improves user experience by indicating that an element is clickable. Below are the approaches to set cursor style to pointer for links without href: Table of Content Using CSS class Using the onmouseover eventApproach 1: Using
    2 min read
  • How to ask the Selenium-WebDriver to wait for few seconds in Java?
    An open-source framework that is used for automating or testing web applications is known as Selenium. There are some circumstances when the particular component takes some time to load or we want a particular webpage to be opened for much more duration, in that case, we ask the Selenium web driver
    9 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences