I am trying to switch between two divs. For example, onload, I want the left content to be displayed and the correct content to remain hidden. If I click on the right div, I want the left content to be hidden and the desired content to appear, and vice versa. I am very new to javascript, but here is what I have. I can't seem to get it to work. Please, help...
Here is my HTML code:
<div onclick="toggle_visibility('left');"> Left </div> <div onclick="toggle_visibility('right');"> Right </div> <div id="left" style="display: block;"> This is the content for the left side <div> <div id="right" style="display: none;"> This is the content for the ride side </div>
Here is the Javascript I am using:
<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>
source share