Why is window.matchMedia not working?
-
Do not laugh. Help: D
JavaScript Lila Lewis, Nov 23, 2020 -
const block = document.querySelector('.block');
const mql = window.matchMedia("(max-width: 768px)");
window.addEventListener('resize', () => {
if (mql.matches) {
block.style.backgroundColor = "blue"
} else {
block.style.backgroundColor = "red"
}
})Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!