Solved

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

Posted on 2010-09-14
4
510 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

617 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