Computer >> Computer tutorials >  >> Programming >> Javascript

How to set the type of cursor to display for the mouse pointer with JavaScript?


To set the type of cursor, use the cursor property in JavaScript. It allows you to change the cursor on button click.

Example

You can try to run the following code to set the type of cursor to display for the mouse pointer with JavaScript −

<!DOCTYPE html>
<html>
   <body>
      <h1 id="myID">Heading 1</h1>
      <p>Check the heading before and after mouse hover.</p>
      <button type="button" onclick="display()">Click to change the cursor</button>
      <script>
         function display() {
            document.getElementById("myID").style.cursor = "pointer";
         }
      </script>
   </body>
</html>