jQuery Test

Seeing why document.ready does not seem to be respected. Stack Overflow question

HTML

<html>
    <body>        
        <form id="form1" method="POST" action="" >
            <input type="hidden" id="userdataexists" value="true" />
            <input type="checkbox" id="foo1" />
            <input type="checkbox" id="foo2" />
            <input type="checkbox" id="foo3" />
            <input type="checkbox" id="foo4" />
            <input type="checkbox" id="foo5" />
        </form>      
    </body>
</html>

CSS

input { display:block; margin-bottom: 1em; }

JavaScript

//set checkbox states on page load if first visit by user
$(document).ready(function() {

    $("#form1 input:checkbox").each(function() {
        if ($("#userdataexists").attr('value') == 'true') {
            $(this).attr('checked', 'true');
        }
    });

});