I am trying to simply show/hide content; by creating an if statement
in plain JS to detect if the current body tag
has a specific class attached; i.e. home
I am trying the below; on the correct page, but am not getting the alert.
var elem = document.querySelector('body');
if (elem.classList.contains('test')) {
alert('test');
}
no jQuery!!
error with the above code is:
Uncaught TypeError: Cannot read property 'classList' of null
I just want this to run on page load