<html>
<head>
<script>alert(document.body.className);</script>
</head>
<body>
something
</body>
</html>
I hope this code may return a classname of the body.
But instead, I get Uncaught TypeError: Cannot read property 'className' of null
Is there some way to get and set classname of the body in head before domready event?
The only way is to append this code to domready event?
Not with JavaScript. You can’t access document.body until the body element exists. It does not exist until virtually the entire page is rendered (because the closing is the second last tag on any page)