Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Element is only read as undefined when I try to assign it a variable?

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!