/ Published in: JavaScript
IE compatible.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<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>
URL: http://marioluevanos.com/playground/Show%20Hide%20with%20Raw%20JS/#