What is the best way to refactor the following script?
<script type="text/javascript">
$(document).ready(function() {
$(".rolesList").hide();
});
$("#legendFunction").click(function() {
$("#divChkUserRoles").toggle('slow');
var text = $("#lblExpandFunction").text() == '+' ? '-' : '+';
$("#lblExpandFunction").text(text);
})
$("#legendMISheet").click(function() {
$("#divChkUserRolesMISheet").toggle('slow');
var text = $("#lblExpandMISheet").text() == '+' ? '-' : '+';
$("#lblExpandMISheet").text(text);
})
</script>
The above script will be applied to the following HTML and ASP.NET code:
<fieldset>
<legend><span id="legendFunction" style="cursor: pointer" title="Click here to toggle show or collapse Function.">
<label id="lblExpandFunction" style="padding: 5px;">+</label>
KengLink Function
</span></legend>
<div id="divChkUserRoles" class="rolesList">
<asp:CheckBoxList ID="UserRoles" runat="server" />
</div>
</fieldset>
<fieldset>
<legend><span id="legendMISheet" style="cursor: pointer" title="Click here to toggle show or collapse MI Sheet.">
<label id="lblExpandMISheet" style="padding: 5px;">+</label>
MI Sheet
</span></legend>
<div id="divChkUserRolesMISheet" class="rolesList">
<asp:CheckBoxList ID="UserRolesMISheet" runat="server" />
</div>
</fieldset>