1

I have been using:

    <script>
function change()
{
document.body.style.cursor="url('xx/xx.cur'),auto";
}
</script>

<div onClick="change()"></div>

It works, but its important that the cursor resets while there is no click so i tried the onBlur, but it didnt work.

At last I found this:

<script type="text/javascript"> 
   function change() { 
   document.body.style.cursor=(document.body.style.cursor=="help") ? "default" : "help"; 
} 
</script> 
</head> 
<body> 
<div onmousedown="change()" onmouseup="change()">  </div> 

which works like a charm, but it failed to replace the cursor standard styles with custom .curs.

Here:

    function change()
{
document.body.style.cursor=(document.body.style.cursor=="url ('xx/xx3.cur')") ? "url ('xx/xx1.cur')" : "url ('xx/xx3.cur')";
}
</script>
</head>
<body>

<div onmousedown="change()" onmouseup="change()" id="container">

Obviously the double parentheses are troublesome. I tried everything without success. Any help apreciated. Thanks in advance.

1 Answer 1

1

I would probably tackle this problem with some simple css magic instead.

Instead of actually assigning body.style.cursor a value with javascript I would toggle a class on the html-tag which in turn shows the correct cursor.

CSS:

html
{
    cursor: default;
}

html.help
{
    cursor: url('help.cur');
}

Javascript:

function change()
{
    $("html").toggleClass("help")
}

Working jsfiddle: http://jsfiddle.net/BV3kn/2/

Sign up to request clarification or add additional context in comments.

7 Comments

Hmm it seems that its not working. Maybe a way to break the double parentheses would do the trick.
Do you get any error-messages at all? Checked console? What double parentheses?
I don't get any errors it just doesn't work. The double parentheses part: document.body.style.cursor=(document.body.style.cursor=="url ('xx/xx3.cur')*<here>*") ? "url ('xx/xx1.cur')" : "url ('xx/xx3.cur')";
After some fiddling around I found out that it takes a while for the mouse-cursor to change unless you move it. But if you move it the selection-cursor becomes the active one. jsfiddle.net/BV3kn/1 Working example though, maybe someone else can give you a better answer, I'm off to bed.
I edited my comment, read it again for better info! :) jsfiddle.net/BV3kn/2
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.