My code:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<div class="content_1">
//Content of first page goes
</div>
<div class="content_2" style="display:none;">
//Content of second page goes here
</div>
<div class="content_3" style="display:none;">
//Third page content goes here
</div>
<p>Pages:
<a href="#" class="button_1"> 1</a>
<a href="#" class="button_2"> 2</a>
<a href="#" class="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");
});
});
</script>
I want to refresh the page on clicking the buttons and show the hidden div. I tried many things but the result was page reload and show the first div again whatever button chosen.
Code above is working well . I want to add extra property to the code. I want page reloads when clicking buttons and keep the div shown.
Example: When click on button "2" I want page to be reloaded and show "//Content of second page goes here"
Edit: Thanks alot @Jan-Drewniak but your idea only solved half of the problem. When I type http:// mysite.com#button_3 as url, page loads the first div not the third. I wish I could make this url work for the third because I want to use this Javascript with the button
<script>
function refreshPage(){
window.location.href = "#button_3";
window.location.reload();
}
</script>
as I think this may satisfy my needs.