Cipher Cipher - 5 months ago 39
Javascript Question

Change the mouse pointer using JavaScript

I wanted to use a script to change the mouse pointer on my website using JavaScript.
It's better done by CSS but my requirement is of a script that can be distributed to many people to embed in the head section of their websites.
Through CSS, this can be manipulated by

cursor: *cursorurl*

How to do the same in JavaScript?


Javascript is pretty good at manipulating css. = *cursor-url*;
 var elementToChange = document.getElementsByTagName("body")[0]; = "url('cursor url with protocol'), auto";

or with jquery:

$("html").css("cursor: url('cursor url with protocol'), auto");

Firefox WILL NOT WORK unless you specify a default cursor after the imaged one!!

other cursor keywords

Also remember that IE6 only supports .cur and .ani cursors.

working sample:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<title>First jQuery-Enabled Page</title>
<style type="text/css">

div {
    height: 100px;
    width: 1000px;
    background-color: red;

<script type="text/javascript" src="jquery-1.3.2.js"></script></head>
hello with a fancy cursor!
<script type="text/javascript">
document.getElementsByTagName("body")[0].style.cursor = "url(''), auto";