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="">
    <input type="checkbox" id="chk" checked />Checkbox
    <script type="text/javascript">
        document.getElementById('chk').style.display = 'none';

As long as the javascript reference to the checkbox is after its declaration it should work just fine.
jQuery reference:

I hope this helps.

Leave a Comment