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.

1

2 Answers 2

3

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.

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

6 Comments

please not that this is equal to body{ cursor:none }. See this question if you want to use the * selector in JavaScript
@WouterJ The good solution here is probably to avoid using *.
yes, I know. That's why I added it as a comment and not as an answer.
@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)
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 ?
|
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.

Comments

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.