Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

Auto show ajax content (something like tabs)

From this question...
http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_23999668.html

I was able to create more buttons to show different content. My problem is I want the visible content to hide after I click other button. (see my current code)

For example, if i click button 1, it will show its content, if I click button2 while content of button 1 is visible, it shout first be hidden before showing the content of button 2 and so on...

Thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $("#block1").hide();
  $('#button1').click(function () {
      $("#block1").slideToggle(300);
    });
  });
 
  $(document).ready(function() {
    $("#block2").hide();
  $('#button2').click(function () {
      $("#block2").slideToggle(300);
    });
  });
 
  $(document).ready(function() {
    $("#block3").hide();
  $('#button3').click(function () {
      $("#block3").slideToggle(300);
    });
  });
  
</script>
<style>
textarea {
	background-color: #FFFFCC;
}
</style>
</head>
 
<body>
<button id="button1">Yahoo</button><button id="button2">Gmail</button><button id="button3">Friendster</button>
 
<div id='block1' >
 
<iframe src ="http://www.yahoo.com" width="100%" height="1000">
  <p>Your browser does not support iframes.</p>
</iframe>
 
</div>
 
<div id='block2' >
 
<iframe src ="http://www.gmail.com" width="100%" height="1000">
  <p>Your browser does not support iframes.</p>
</iframe>
 
</div>
 
<div id='block3' >
 
<iframe src ="http://www.friendster.com" width="100%" height="1000">
  <p>Your browser does not support iframes.</p>
</iframe>
 
</div>
 
</body>
</html>

Open in new window

0
antontolentino
Asked:
antontolentino
1 Solution
 
hard2u2001Commented:
Try this:

$(document).ready(function() {
					$("#block1,#block2,#block3").hide();
					$("#button1").bind("click",function(){
						$("#block1,#block2,#block3").hide();
						$("#block1").show();
					});
					$("#button2").bind("click",function(){
						$("#block1,#block2,#block3").hide();
						$("#block2").show();
					});
					$("#button3").bind("click",function(){
						$("#block1,#block2,#block3").hide();
						$("#block3").show();
					});
			});
			

Open in new window

0
 
antontolentinoAuthor Commented:
Thanks...

works like a charm...

 :)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now