I am trying to get the body's classname to use in an if/else statement in plain javascript.
To my surprise the element.className
trows me errors everytime:
Uncaught TypeError: Cannot read property 'className' of undefined
alert( document.getElementsByTagName("body")[0].className.match("home") );
alert( document.getElementById("container").className.match("fooclass") );
<body class="home page">
<div id="container" class="fooclass"></div>
</body>
`
– Dmitriy Mar 10 '16 at 09:04