DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Toggle An Element's Display

  • submit to reddit
        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

function toggle(){
	var div1 = document.getElementById('div1')
	if ( == 'none') { = 'block'
	} else { = 'none'


Snippets Manager replied on Thu, 2007/09/13 - 12:56pm

WoW, A very useful resource to mark it and use. BBV