I have a div that appears when a checkbox is checked, and hides when unchecked. If the form has errors, the page reloads and the div appears hidden even if the checkbox was checked before submission. I can add a call to the onLoad event, but is there a cleaner way to ensure that, after page reload, the div is rendered based on the status of the checkbox?
Css:
#maintenance-window { display: none; }
jQuery:
$("#check-hasMaintenance").click(function() {
$(this).is(":checked") ? $('#maintenance-window').show("fast") : $('#maintenance-window').hide("fast")
});
HTML:
<input type="checkbox" value="1" id="check-hasMaintenance">
<div id="maintenance-window">
Stuff
</div>
Option 1
Ensure div is shown based on check box when the page loads:
Simplified hide/show code:
Option 2
A short-hand version like this should work as well: