Skip to content
Advertisement

Why doesn’t this code display the button after I hide it?

When I run this JavaScript code, button2 doesn’t get displayed again. I’m not sure why this is happening. I am trying to use this in a game I am creating. I searched this up on Google multiple times and couldn’t find an answer.

JavaScript

Advertisement

Answer

There is no auto display is CSS. As tarkh mentioned in his answer, display block would insert the new button below the initial button, and other display options would have other behaviors. But the display property does not have a value auto.

This may be my opinion, but I think modern websites shouldn’t use the onclick function for events. We should separate our HTML, JS and CSS. This helps with reusability. https://en.wikipedia.org/wiki/Unobtrusive_JavaScript

So I would create a solution that uses an event handler in the Javascript. Something like:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement