0

My script:

    window.onload = addAutoplay();
    var videoLocation  = document.getElementById("home-vide");
    function addAutoplay() {
        if(window.innerWidth >992){
            videoLocation.setAttribute("autoplay","");
      };
    }

Is giving the following error:

Uncaught TypeError: Cannot read properties of undefined (reading 'setAttribute')
    at addAutoplay ((index):362:18)
    at (index):358:18

When I try to debug this in the console, I can see that document.getElementById("home-vide"); correctly grabs the video, but trying to assign it to a variable results in undefined. Not sure why this is?

enter image description here

AC1
  • 63
  • 1
  • 2
  • 7

0 Answers0