I have a page with a few sections in it like the snippet below, and a menu that hides or displays the different sections.
However, I have a form on one section which when submitted refreshes the page, therefore the section displayed goes back to the first section but I want to keep it on the section where the from was submitted.
Is there an easy way to do this or will I need to do something in JS where there is a hidden input in the form that tells it which section should be displayed after it is submitted?
$("#menu li:nth-child(1)").unbind("click").bind("click", function() {
$("#section1").css("display", "block");
$("#section2").css("display", "none");
$("#section3").css("display", "none");
});
$("#menu li:nth-child(2)").unbind("click").bind("click", function() {
$("#section1").css("display", "none");
$("#section2").css("display", "block");
$("#section3").css("display", "none");
});
$("#menu li:nth-child(3)").unbind("click").bind("click", function() {
$("#section1").css("display", "none");
$("#section2").css("display", "none");
$("#section3").css("display", "block");
});
#menu li {
display: inline-block;
}
#section1 {
display: block;
background-color: #d33;
}
#section2 {
display: none;
background-color: #3d3;
}
#section3 {
display: none;
background-color: #33d;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<ul id="menu">
<li>Menu1</li>
<li>Menu2</li>
<li>Menu3</li>
</ul>
<div id="section1">
Section 1
</div>
<div id="section2">
Section 2
<form><button>Submit</button></form>
</div>
<div id="section3">
Section 3
</div>