Category Archives: JavaScript

How to hide and show elements with JavaScript (updated)

webThere are times that we just want to hide an element first, and shows it later when the user performs something like clicking a button.

Implementing this functionality with JavaScript is quite easy. (On a side note, there is a really great section on Embedding JavaScript in HTML in JavaScript: The Definitive Guide: Activate Your Web Pages. If you don’t have that book, you really should.)
The strategy is to place the controlled element on a hidden layer (div), and then change the display attribute to make it show up.

First, Let’s define a variable, which tells if the video should be shown, in JavaScript.
Continue reading