Does the HTML spec guarantee that DOM elements appearing before a <script> tag are present before the content of that script is executed (and can be manipulated by that script)?
This works in all browsers I've tested, but I'm not sure whether it's legal:
<main hidden>Hello, world</main>
<script type="text/javascript">
document.querySelector('main').hidden = false; // no error thrown
</script>
I know that the script will execute immediately, blocking parsing, unless it has the async or defer attributes.
But does the parsing up until this point guarantee that the prior elements are in the DOM and ready to be manipulated, or is it safest to wait for DOMContentLoaded?