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

03.20.2006
| 128882 views |
  • 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
</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

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

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