Javascript open close toggle div. <alebal web Blog> | Appunti di PHP, MySql, javascript, Css, HTML, HTML5 e altro...

A small Javascript script that allows, for example, open, close or toggle a div.

Using only Javascript, no jquery, no mootools, no angularjs, no dojo, nothing... only Javascript.

<script type="text/Javascript">
function Show(id){
function Hide(id){
function toggle(id) {
		if(document.getElementById(id).style.display == 'block')
			document.getElementById(id).style.display = 'none';
			document.getElementById(id).style.display = 'block';

It is used like this:

<div id="id1" style="display:none;">id1</div>
<div id="id2">id2</div>
<div id="id3">id3</div>

<a href="Javascript:void(0)" onclick="Show('id1'); Hide('id2'); toggle('id3'); return(false);">

In this example on a link, but can be used almost everywhere.

I know it's a lot easier than I usually post, and that perhaps there was no need to write it. But I never remember where I used last time, and every time I need to find it I become an idiot. Now I found here ...

Google Digg Reddit Tumblr Pinterest StumbleUpon Email

Rating: 4 out of 5 by 830 visitors

Leave your comment