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

JavascriptWeb DevelopmentFront End Scripts

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 −

Live Demo

<!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>
raja
Published on 27-Feb-2018 16:35:02
Advertisements