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

LVL 9
antontolentinoAsked:
Who is Participating?
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.