Click here to Skip to main content
15,921,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a web application that loads div pages in a div container but when i refresh that page the div goes to the first loaded div. i would like to keep the current selected div even after page is refreshed. Any help will be apricated.

What I have tried:

&&
$('ul#nav li a').click(function(){
				var page = $(this).attr('href');
               var sp = $("#sp").val();
 var mo = $("#mo").val();   
 var ut = $("#ut").val();
				$('#main-content').load(''+ page +'.php', {sp: sp,ut: ut,mo: mo});
				return false;
			});
Posted
Updated 23-Mar-22 9:33am

1 solution

You could use JavaScript to save a flag value in localStorage then, if the value exists you can set the div properly.
See the localStorage api at: Window.localStorage - Web APIs | MDN[^]

JavaScript
localStorage.setItem("makeDiv1st","my-divId");

Then next time page loads you check the value:
JavaScript
let targetDivId = localStorage.getItem("makeDiv1st");



This should all probably be done without the page refresh but this is one workaround that may work for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900