Return to Snippet

Revision: 35650
at November 11, 2010 10:47 by bullzito


Initial Code
<script type="text/javascript">

//create reusable event function
function addEvent( id, event, fn, capture ) {
	if (id.addEventListener) {
		if (!capture) capture = false;
		id.addEventListener(event, fn, capture);
	}
	else {
		id.attachEvent('on' + event, fn);
	}
}

//variables to get the ID
var	a = document.getElementById('toggle'),
	box = document.getElementById('box');

	//set the display to "block"
	box.style.display = 'block';

//our main function to show & hide
function showHide(e) {
	if ( box.style.display == 'block' ) {
		box.style.display = 'none';
		a.style.borderBottom = '1px solid #000';
	}
	else {
		box.style.display = 'block';
		a.style.borderBottom = 'none';
	}
}

//call the addEvent function with parameters
addEvent(a, 'click', showHide, false);

</script>

Initial URL
http://marioluevanos.com/playground/Show%20Hide%20with%20Raw%20JS/#

Initial Description
IE compatible.

Initial Title
Show & Hide with Raw JavaScript

Initial Tags


Initial Language
JavaScript