HerraE
HerraE

Reputation: 107

Hide an HTML <img ...> with javascript

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 :)

Upvotes: 0

Views: 76

Answers (5)

kei
kei

Reputation: 20521

startButton.onclick = function()
{
   startButton.style.visibility="hidden";
   /* OR
   startButton.style.display="none";
   */
   alert('Game starts!');
}

Upvotes: 0

blueygh2
blueygh2

Reputation: 1538

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.

Upvotes: 0

beercodebeer
beercodebeer

Reputation: 990

Adding this after the alert seems to work.

this.style.display = 'none';

updated Fiddle

Upvotes: 2

chepe263
chepe263

Reputation: 2812

try

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

HTMLElement.style reference (MDN)

Upvotes: 0

hairmot
hairmot

Reputation: 2965

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

Upvotes: 0

Related Questions