Solved

Show layer in another layer place, and hide the new layer from button

Posted on 2010-09-14
4
505 Views
Last Modified: 2012-05-10
Hi all,


I have Button A and aside, Layer 1 to start with.
If I click Button A I need Layer 1 to hide and Layer 2 to be shown in its place.
Inside of Layer 2 there's Button B.
If I click Button B, Layer 2 has to hide and Layer 1 has to show in it's place.

The attached image will give you a further view.

How can I do this? I was about to post some of my code but the only thing I have come around is to show and hide from the same button :(

Thanks a lot!

 
showHideLayers.gif
0
Comment
Question by:Dada44
4 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 33670028
<script type="text/javascript">
function showHide(showing,hiding) {
  document.getElementById(showing).style.display="";
   document.getElementById(hiding).style.display="none";
 }
</script>
<input type="button" onClick="showHide('div2','div1')" value="ButtonA" />
 <div id="div1" style="position:absolute; top:0; left:200px">I'm Layer1</div>
 <div id="div2" style="position:absolute; top:0; left:200px; display:none">I'm Layer2<br/><input type="button" onClick="showHide('div1','div2')" value="ButtonB" /></div>
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 33670070
Assuming that 2 layers are
<div id="layer1" style="left:100px; top:20px;"\>
<div id="layer2" style="left:100px; top:40px;"\>

<a id='buttonA'>
<a id='buttonB'>

$("#buttonA").bind("click", function(){
   var layer1 = $("#layer1");  
   var layer2 = $("#layer2");  
   var left = layer1.css("left");
   var top = layer1.css("top");
   $("#layer1").css ("display", "none");
   $("#layer2").css ("left", left + "px");
   $("#layer2").css ("top", top + "px");
 
});

$("#buttonB").bind("click", function(){
   var layer2 = $("#layer1");  
   var layer1 = $("#layer2");  
   var left = layer1.css("left");
   var top = layer1.css("top");
   $("#layer1").css ("display", "none");
   $("#layer2").css ("left", left + "px");
   $("#layer2").css ("top", top + "px");
 
});
0
 

Author Closing Comment

by:Dada44
ID: 33670093
Awesome! thank you!
0
 
LVL 14

Expert Comment

by:sam2912
ID: 33670369
Since you are using jQuery, this is a better way to do it


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<style type="text/css">

#div1, #div2 {

   position:absolute;

   top:150;

   left:150px;

   margin: 10px;

   padding: 10px;

   border: 2px solid gray;

}

</style>

<script type="text/javascript">

$(document).ready(function(){

	$('#div2').css('display','none');

	$('#buttonA').click(function() { $('#div1').css('display','none'); $('#div2').css('display',''); });

	$('#buttonB').click(function() { $('#div2').css('display','none'); $('#div1').css('display',''); });

});

</script>

<input type="button" id="buttonA" value="Button A" />

<div id="div1">I'm Layer1</div>

<div id="div2">I'm Layer2<br/><input type="button" id="buttonB" value="Button B" /></div>

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now