0

I want to hide the cursor for my browser based game. I don't want to do this until the game starts.

I have this in CSS: * { cursor: none }. How would I do this in JavaScript? My target browser is Chrome and only Chrome.

Mr_Green
  • 40,727
  • 45
  • 159
  • 271
Cheetah
  • 13,785
  • 31
  • 106
  • 190
  • See here: http://stackoverflow.com/questions/1071356/is-it-possible-to-hide-the-cursor-in-a-webpage-using-css-or-javascript#1071363 – looper Feb 22 '13 at 12:26

2 Answers2

2

You can do

document.body.style.cursor='none';

A note about your CSS : it's better to avoid as much as possible the * selector, especially when you can just set a style to the body.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • 2
    please not that this is equal to `body{ cursor:none }`. See [this question](http://stackoverflow.com/a/4256372/1149495) if you want to use the `*` selector in JavaScript – Wouter J Feb 22 '13 at 12:29
  • 1
    @WouterJ The good solution here is probably to avoid using `*`. – Denys Séguret Feb 22 '13 at 12:31
  • 2
    yes, I know. That's why I added it as a comment and not as an answer. – Wouter J Feb 22 '13 at 12:33
  • 1
    @dystroy Using the body does not work for hyperlinks (as an example, might not work for other objects too....hence why I want the * selector) – Cheetah Feb 22 '13 at 12:53
  • I thought this was for a full window game, which made some sense... Do you really really want to hide the cursor over the links and the inputs ? Is the goal to piss the users ? – Denys Séguret Feb 22 '13 at 13:07
  • @dystroy what I am doing would not affect the users (who will watch an induction video anyways), other that aesthetics. – Cheetah Feb 22 '13 at 13:12
1
<div id="nocursor"></div>

<script type="text/javascript">
    document.getElementById('nocursor').style.cursor = 'none';
</script>

It still uses css, but I assume that this is what you were looking for.

Shelef
  • 598
  • 2
  • 8
  • 16