0

I am trying to make a simple game about sliding ice-blocks. However, I tested this JSFiddle and I want to "hide" the image/button on the line alert('Game starts!');. I tried startButton.style = "visibility: hidden;"; but it didn't work...

I only need to resolve this problem, I know how to code the game itself :)

5 Answers 5

2

Adding this after the alert seems to work.

this.style.display = 'none';

updated Fiddle

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

1 Comment

Nice it worked, thanks :) Is there any possibility, to write the "onclick-function" into a own .js data or do I really have to write this in a <script> tag?
0

try document.getElementById("startButton").style.display="none"

Comments

0

try

 document.getElementById("startButton").style.visibility = 'hidden';

HTMLElement.style reference (MDN)

Comments

0

You can also use jQuery UI, which has a "hide" method. You can then simply say $('.startButton').hide() You can even apply different effects.

However, this will set the visibility to none, removing the object from the DOM. If you don't care about that, it's fine, but it should be borne in mind.

1 Comment

Another advantage of using jQuery is that you don't have to write all the specialised code that ensures it runs in every single possible browser - jQuery does most of it for you
0
startButton.onclick = function()
{
   startButton.style.visibility="hidden";
   /* OR
   startButton.style.display="none";
   */
   alert('Game starts!');
}

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.