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

136
Vistas
document.querySelectorAll doesn't apply despite the HTML adjusting

I'm trying to get all the divs within a div with document.querySelectorAll. Interestingly, when I set in the JS the height to 1000, the explorer's scroller enlarges accordingly (only the balloon doesn't get bigger). What am I doing wrong?

'use strict';

var gElBalloons;

function init() {
  gElBalloons = document.querySelectorAll('.balloons');

  setInterval(moveBalloons, 1000);
}

function moveBalloons() {
  for (var i = 0; i < gElBalloons.length; i++) {
    gElBalloons[i].style.height = 1000 + 'px';
  }
}
body {
  margin: 10%;
}

.balloon-1 {
  display: block;
  width: 120px;
  height: 145px;
  background-color: red;
  border-radius: 80%;
  position: absolute;
}

.balloon-2 {
  display: block;
  width: 120px;
  height: 145px;
  background-color: blue;
  border-radius: 80%;
  left: 40%;
  position: absolute;
}
<!DOCTYPE html>

<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Balloons</title>
  <link rel="stylesheet" href="./css/main.css" />
</head>

<body onload="init()">
  <div class="balloons">
    <div class="balloon-1"></div>

    <div class="balloon-2"></div>
  </div>
  <script src="./js/main.js"></script>
</body>

</html>

For now, I just want to test and make sure it works correctly.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It seems that your selector selected the wrong div. If you want to make the ball bigger, you should select balloon-1 and balloon-2 instead of their container balloons.

'use strict';

var gElBalloons;

function init() {
  gElBalloons = document.querySelectorAll('.balloons > div');

  setInterval(moveBalloons, 1000);
}

function moveBalloons() {
  for (var i = 0; i < gElBalloons.length; i++) {
    gElBalloons[i].style.height = 1000 + 'px';
  }
}
body {
  margin: 10%;
}

.balloon-1 {
  display: block;
  width: 120px;
  height: 145px;
  background-color: red;
  border-radius: 80%;
  position: absolute;
}

.balloon-2 {
  display: block;
  width: 120px;
  height: 145px;
  background-color: blue;
  border-radius: 80%;
  left: 40%;
  position: absolute;
}
<!DOCTYPE html>

<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Balloons</title>

</head>

<body onload="init()">
  <div class="balloons">
    <div class="balloon-1"></div>

    <div class="balloon-2"></div>
  </div>

</body>

</html>

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