Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Toggle an element's display (See related posts)

Sometimes you have a content that shouldn't display
by default. You can provide a link to display/hide
that content
<a href='javascript: toggle()'>toggle</a>
<div id='div1' style='display:none'>
Don't display me
</div>

<script>
function toggle(){
	var div1 = document.getElementById('div1')
	if (div1.style.display == 'none') {
		div1.style.display = 'block'
	} else {
		div1.style.display = 'none'
	}
}
</script>

Comments on this post

shaid posts on Sep 13, 2007 at 14:05
WoW, A very useful resource to mark it and use.
BBV

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts