I want to refresh the page on clicking the buttons and show the hidden div. My code below is working well. I want to add extra property to the code. I want page reloads when clicking buttons and keep the chosen div shown. Example: When click on button "2" I want page first to be reloaded and second to show "//Content of second page goes here"
My code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div id="content_1">
//Content of first page goes here
</div>
<div id="content_2" style="display:none;">
//Content of second page goes here
</div>
<div id="content_3" style="display:none;">
//Third page content goes here
</div>
<p style="font-weight:bold;">Pages:
<a href="#button_1" id="button_1"> 1</a>
<a href="#button_2" id="button_2"> 2</a>
<a href="#button_3" id="button_3"> 3</a>
</p>
<div class="clearLeft"></div>
<script type="text/javascript">
$(document).ready(function(){
var a = 200;
$('#button_1').css("background-color","#00CCFF");
$('#button_1').click(function(){
$('#content_1').fadeIn(a);
$('#content_2').fadeOut();
$('#content_3').fadeOut();
$('#content_4').fadeOut();
$('#button_1').css("background-color","#00CCFF");
$('#button_2').css("background-color","#99FF99");
$('#button_3').css("background-color","#99FF99");
$('#button_4').css("background-color","#99FF99");
});
$('#button_2').click(function(){
$('#content_1').fadeOut();
$('#content_2').fadeIn(a);
$('#content_3').fadeOut();
$('#content_4').fadeOut();
$('#button_2').css("background-color","#00CCFF");
$('#button_1').css("background-color","#99FF99");
$('#button_3').css("background-color","#99FF99");
$('#button_4').css("background-color","#99FF99");
});
$('#button_3').click(function(){
$('#content_1').fadeOut();
$('#content_2').fadeOut();
$('#content_3').fadeIn(a);
$('#content_4').fadeOut();
$('#button_3').css("background-color","#00CCFF");
$('#button_1').css("background-color","#99FF99");
$('#button_2').css("background-color","#99FF99");
$('#button_4').css("background-color","#99FF99");
});
$('#button_4').click(function(){
$('#content_1').fadeOut();
$('#content_2').fadeOut();
$('#content_3').fadeOut(a);
$('#content_4').fadeIn();
$('#button_4').css("background-color","#00CCFF");
$('#button_1').css("background-color","#99FF99");
$('#button_2').css("background-color","#99FF99");
$('#button_3').css("background-color","#99FF99");
});
});
</script>
<script>
var urlHash = window.location.hash
$(urlHash).trigger('click')
</script>
<style>
.pages
{
position:relative;
top:20px;
font:1.1em Arial, Helvetica, sans-serif;
color:#000033;
font-weight:bold;
width:200px;
margin:0px auto;
}
.pages ul
{
marging:0px;
padding:0px;
}
.pages li
{
list-style-type:none;
float:left;
margin-left:5px;
}
.pages li a
{
padding:5px 7px 7px 5px;
border:1px solid #999999;
background-color:#99FF99;
text-decoration:none;
display:block;
}
.pages li a:hover
{
background-color: #00CCFF;
}
.clearLeft
{
clear:left;
}
.clearRight
{
clear:right;
}
</style>