I am trying to make this if statement work to meet the requirement of meeting the mediaQuery AND checking if the body contains a specific className. But it results in defaulting to the else statement, "Lower than 799px". How can I make this if statement work?...Cheers!
const mediaQueryList = window.matchMedia('(min-width: 50em)')
function() {
//do stuff
}
function handleDeviceChange(e) {
if (e.matches && document.body.classList.contains('className') {
console.log('Media Query above 800px')
function();
} else {
console.log('Media Query: lower then 799px')
}
}
mediaQueryList.addEventListener('change', handleDeviceChange);
handleDeviceChange(mediaQueryList);
Aucun commentaire:
Enregistrer un commentaire