saudiqbal Posted March 17 Posted March 17 https://www.w3schools.com/howto/howto_js_vertical_tabs.asp Now the browser remembers which tab was selected last on page reload. function openTabs(evt, cityName) { var i, tabcontent, tablinks; tabcontent = document.getElementsByClassName("tabcontent"); localStorage.setItem("SelectedTab", cityName); for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; } tablinks = document.getElementsByClassName("tablinks"); document.getElementById(cityName).style.display = "block"; } var currentTab = localStorage.getItem("SelectedTab"); // If the current local storage item can be found if (currentTab) { //document.getElementById(currentTab).click(); openTabs(event, currentTab); } else { // Get the element with id="defaultOpen" and click on it document.getElementById("defaultOpen").click(); var defaultTab = document.getElementById("defaultOpen"); localStorage.setItem("SelectedTab", 'Tools'); }
saudiqbal Posted March 18 Author Posted March 18 <li onclick="openTabs(event, 'Tools')" id="defaultOpen">Tools</li> <li onclick="openTabs(event, 'Logs')">Logs</li> <li onclick="openTabs(event, 'Files')">Files</li> <li onclick="openTabs(event, 'Links')">Links</li>
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now