Change the cursor with Javascript

Posted in Javascript -

This post shows how to change the cursor on a web page with Javascript by assigning a value to the property.

Assign a value to

Assign one of the cursor properties to to change the cursor. The first example below will change the cursor to an hourglass: = "wait";

The second example restores it back again by assigning "default" to the cursor property: = "default";

Working Example

The following select box and button can be used to change the cursor. If you are viewing this post in an RSS reader you will probably need to click through to view this in a web browser for the example to work.

Example Code

Here's the code behind the example above:

<script language="Javascript">
	function example_change_cursor() { = document.getElementById('example-cursor').options[document.getElementById('example-cursor').selectedIndex].value;
	function example_restore_cursor() { = 'default';
<select id="example-cursor">
<input type="button" onclick="example_change_cursor()" value="Change Cursor" />
<input type="button" onclick="example_restore_cursor()" value="Restore Default" />

Related posts: