Change mouse cursor in Javascript or jQuery
60,394
Solution 1
Do it in both html
and body
:
$('html,body').css('cursor','crosshair');
Solution 2
It does work, but you had an empty body.
HTML
<body>
asdasdasdasdads
</body>
JS
document.body.style.cursor = "crosshair";
Solution 3
document.getElementById("mydiv").style.cursor="move";
Related videos on Youtube
Author by
Arnaud
Updated on July 09, 2022Comments
-
Arnaud almost 2 years
How can I change the mouse cursor in Javascript or in jQuery ? I know it's a very classic question, but very strangely this JSFiddle doesn't work : http://jsfiddle.net/2Qffw/.
Here is the code :
$('body').css('cursor','pointer'); document.body.style.cursor = "pointer";
-
adeneo almost 11 yearsTry locally without jsFiddle, and it should work, or try an element in jsFiddle and it works as well -> jsfiddle.net/2Qffw/1
-
cirrus almost 11 yearsThe nicest way of doing this is with a CSS rule using :hover. Can you model your app that way instead?
-
Arnaud almost 11 years@adeneo : locally, it works without <!DOCTYPE html>, but not with.
-
Arnaud almost 11 years@cirrus : it's not really my problem. In fact, I've largely reduced my problem to that I presented in my question.
-
Corion almost 11 yearsThis doesn't seem like something you should be doing with jQuery instead of plain old CSS.
-
JBH over 6 years@Corion, not true. CSS only restricts the change to only the item over which you are pointing. That's capricious unless it's the body or HTML, then it's permanent. I'm here to find a way to change the cursor while a file is uploading, and then change it back when the upload is complete. That's not a CSS problem.
-