I'm a beginner in JQuery. In my application I have the following:
Here is my HTML code:
<ul id="list">
<li>
<a class="selected" value="0" href="#" id="sel">ALL</a>
</li>
<li>
<a href="#" value="1">1+</a>
</li>
<li>
<a href="#" value="2">2+</a>
</li>
<li>
<a href="#" value="3">3+</a>
</li>
<li>
<a href="#" value="4">4+</a>
</li>
<li>
<a href="#" value="5">5+</a>
</li>
</ul>
<input type="hidden" id="hdn_list" value=""></input>
This is my CSS code:
.selected{background-color:green;}
Below is my JQuery code for retrieving the selected list value:
$(document).ready(function () {
$('#list li a').click(function () {
var listValue = $(this).attr("value");
$("#hdn_list").value = listValue; //passing the new selected values to hidden control
$('#list li a').removeClass('selected');
$(this).addClass('selected');
return false;
});
});
When I click the submit button, it redirects to the next page. If I go back to this page, it should pre-fill the selected value using the hidden control (#hdn_list) value and apply the CSS style to that selected value. How can I achieve this using jQuery/javascript? Thank you in advance.