4 ms·
I did it the other way around. I put this at the start of <body>: <script>document.body.classList.add("hasJS");</script> And the corresponding CSS: .
by grishka 2y ago
I did it the other way around. I put this at the start of <body>:
<script>document.body.classList.add("hasJS");</script>
And the corresponding CSS:
.js{display: none;}
.hasJS .js{display: block;}
- MrJohz 2y agoThis has the advantage compared to OP's solution that it will also work if JS doesn't load correctly (as opposed to if it is blocked/deliberately not loaded). You can add this line to the end of the main JS file that you're including on your page, and it will ensure that the JS "switch" will only get triggered if that file could be downloaded and parsed.
- deleted 2y ago[deleted]