I'm doing this over and over, and I'm not sure if it is the best way to do so in JavaScript/jQuery. I have a function that acts as an event handler, but also I need to call it on page initialization. Thus I have been using the following code:
<script type="text/javascript">
$(function() {
function doToggle() {
$("#toggle-fields").toggle(!$('#checkToggle').is(':checked'));
}
doToggle();
$('#checkToggle').click(doToggle);
});
</script>
How do you tackle this repetitious situation? Are there any best practices that you can point me toward?