Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda