Monday, January 10, 2011

Toggle Visibility - Javascript

Simply paste this javascript under the "<body>" tag

<script type="text/javascript">

<!--

function toggle_visibility(id) {

var e = document.getElementById(id);

if(e.style.display == 'block')

e.style.display = 'none';

else

e.style.display = 'block';

}

//-->

</script>




Example of executing it can see below



<a href="#" onclick="toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>

<div id="foo">This is foo</div>

No comments:

Post a Comment