Why is window.matchMedia not working?

  • 0
    Do not laugh. Help: D
    JavaScript Lila Lewis, Nov 23, 2020

  • 1 Answers
  • 0
    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

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!