Checkbox hidden on body load [closed]

I think you’re looking for document.onready which is available using jQuery, but to keep it with javascript, as in your question, I suggest you move your javascript call to the end of the document. The onload will execute before the checkbox is rendered, that’s why you’re getting the error.

Try the following approach:

<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
    <input type="checkbox" id="chk" checked />Checkbox
    <script type="text/javascript">
        document.getElementById('chk').style.display = 'none';
    </script>
</body>
</html>

As long as the javascript reference to the checkbox is after its declaration it should work just fine.
jQuery reference: http://api.jquery.com/ready/

I hope this helps.

Browse More Popular Posts

Leave a Comment