Check if body has a certain class

var body = document.querySelector('body');

if (document.body.classList.contains('home')) {
	body.classList.remove('list-view');
	body.classList.add('grid-view');
}

if you dont get anything, make sure the script is loading after the dom content.

 

And with Jquery:
if ($("body").hasClass("home")) {
    //Do something
}

Leave a Reply

Your email address will not be published. Required fields are marked *