Link to home
Start Free TrialLog in
Avatar of antontolentino
antontolentinoFlag for United Arab Emirates

asked on

Auto show ajax content (something like tabs)

From this question...
https://www.experts-exchange.com/questions/23999668/how-do-I-hide-and-show-a-form-using-JS-and-or-AJAX.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

ASKER CERTIFIED SOLUTION
Avatar of hard2u2001
hard2u2001

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of antontolentino

ASKER

Thanks...

works like a charm...

 :)