I need to hide a few things when a checkbox is checked, and show them when checkbox is unchecked. I use a class selector to go through the documents and hide these elements.
The code seems to work, the only problem is each time the page is loaded, when I check it, the change event does not fire. I have to un-check, then check again, then the event fires. Please help me see what I did wrong.
<script type="text/javascript">
$(document).ready(function () {
$('#chkFiles').change(function () {
if (this.checked)
$(".hideWhenChecked").hide();
else
$(".hideWhenChecked").show();
});
});
</script>
The elements to be hidden are like this:
<TR>
<TD style="WIDTH: 144px" width="144"><span class="hideWhenChecked">Select:</span></TD>
<TD><span class="hideWhenChecked"><asp:dropdownlist id="ddl" runat="server" AutoPostBack="True"></asp:dropdownlist></span></TD>
</TR>
Our jquery library is 1.4.1, it's old, but it's not up to me to make the decision to update it. Some functionality are not available in this version.