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

159
Views
Cannot set properties of undefined (setting 'left')

i'm trying to move the ball to right but i got this error : Cannot set properties of undefined (setting 'left') i tried to search but all the answers says that my code is correct

var ballSpeed = 3;
var ballPosition = 0;
var ballTime = 1;
var ball = $('#ball');


function bT() {
  ballPosition = ballPosition + ballSpeed;
  ball.style.left = ballPosition + "px";
}

var ii =setInterval(bT, 1);
console.log(ii);
.window{
  background-color: #00FFDD;
  height:100vh;
  margin: 0px;
}

#ball{
  position: absolute;
  height: 100px;
  width: 100px;
  border-radius: 50%;
  background-color: red;
}
<!DOCTYPE html>
   
  <body>
<div class="window">
<div id="ball"></div>
</div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="index.js" charset="utf-8"></script>
  </body>
</html>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use this instead:

var ballSpeed = 3;
var ballPosition = 0;
var ballTime = 1;
var ball = $('#ball');


function bT() {
  ballPosition = ballPosition + ballSpeed;
  ball.css('left', ballPosition);
}

var ii =setInterval(bT, 1);
console.log(ii);
.window{
  background-color: #00FFDD;
  height:100vh;
  margin: 0px;
}

#ball{
  position: absolute;
  height: 100px;
  width: 100px;
  border-radius: 50%;
  background-color: red;
}
<!DOCTYPE html>
   
  <body>
<div class="window">
<div id="ball"></div>
</div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="index.js" charset="utf-8"></script>
  </body>
</html>

Modifying a JQuery element's style uses the .css() method, as outlined here.

about 4 years ago · Juan Pablo Isaza Report
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!