jeudi 29 janvier 2015

jQuery not adding class to body


I'm trying to add a class to the body when someone is viewing the page on a mobile device. I have got the mobile detection down, but for some reason jQuery won't add a class to the body tag. I am stumped as to why it isn't working. I get the alert with 2nd but no mobile class.



(function () {
var NO_REDIRECT = 'noredirect'; // cookie to prevent redirect
// I only want to effect phones
if (isMobile.any) {
alert('1st')
// Only redirect if the user didn't previously choose
// to explicitly view the full site. This is validated
// by checking if a "noredirect" cookie exists
if ( document.cookie.indexOf(NO_REDIRECT) === -1 ) {
alert('2nd');
$(document.body).addClass('mobile');
}
}
})();




Aucun commentaire:

Enregistrer un commentaire