Hi guys,

Im having a problem with some code here.

I have 2 divs and 2 buttons. I want 1 dive to hide and 1 display when i click one button. And when I click the other button the other div displays/hides.

I'm using the below code but it just won't work for me. Any help would be great!

<script type="text/javascript">
				function toggle_view(show,hide){
					var x = document.getElementById(show);
					var y = document.getElementById(hide);
					
					x.style.display = "block";
					y.style.display = "";
				}
			</script>

Here's my div's code:

<div id="carousel_toggle_top">
[contents]
</div>

<div id="carousel_toggle_special">
[contents]
</div>

Recommended Answers

All 3 Replies

I'm assuming "show" and "hide" are variables that are equal to "carousel_toggle_top" and "carousel_toggle_special", respectively? If not, you need to put "carousel_toggle_top" in the x getElement and "carousel_toggle_special" in the y getElement, with the qoutes. And I would use "none" instead of "" for the display style.

Oh yes I forgot to add these:

<a href="#" onclick="toggleview('carousel_toggle_top','carousel_toggle_special');return false;">

<a href="#" onclick="toggleview('carousel_toggle_special','carousel_toggle_top');return false;">

You have an under score in "toggleview" when the function is defined but no not when you call the function. I going to say the that will solve your problem. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.