Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I change my mouse pointer with JavaScript?

Cursor Manipulation

How do I change my mouse pointer with JavaScript?

by  Einstein47  Posted    (Edited  )
Your mouse pointer (cursor) is just another element on a web page. You can control many aspects of how it looks in response to different events on your web page.

Let's say you have a form that takes a few seconds to process and you want to let your users know not to keep clicking the "submit" button. You can very simply add the following to the <FORM> HTML tag:
[color blue]
Code:
<FORM ... onsubmit="document.body.style.cursor='wait'">
[/color]
Be aware that this will not work on older versions of browsers - [color blue]your mileage may vary, see dealer for details.[/color] But the nice thing is that with a single line you can tell your users that something is happening.

Here is a list of possible cursors you can use:
[ul]
[li]auto[/li]
[li]crosshair[/li]
[li]default[/li]
[li]pointer (hand in IE 5.x)[/li]
[li]help[/li]
[li]move[/li]
[li]text[/li]
[li]wait[/li]
[li]e-resize, w-resize, n-resize, s-resize, ne-resize, nw-resize, se-resize, sw-resize[/li]
[/ul]
These values can be assigned with the onmouseover / onmouseout event handlers for any image or page element. For example add this to an image on your page:
[color blue]
Code:
<IMG src=".." ... onmouseover="this.style.cursor='crosshair';">
[/color]
Hopefully you can experiment with cursor control and let it be another extension of your web pages.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top