In my implementation based on this example code from https://www.w3schools.com/howto/howto_js_tabs.asp, I have a specific requirement. I want the tab for "Paris" to remain active even after the page is refreshed if the user has clicked on the button for "Paris".
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">Enrollment</button>
<button class="tablinks" onclick="openCity(event, 'Paris')" id="secondOpen" >Student</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')" id="thirdOpen">Parents</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
<script>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
// Is this correct?
first = document.getElementById("defaultOpen");
second = document.getElementById("secondOpen");
third = document.getElementById("thirdOpen");
if (second == ('active')){
document.getElementById("secondOpen").click();
}else if(third == ('active')){
document.getElementById("thirdOpen").click();
}else{
document.getElementById("defaultOpen").click();
}
</script>
This piece of HTML serves as an example, with the main focus on ensuring that the "Paris" tab remains active even after a page refresh when selected by the user.