The HTML changes are not reflected in the document.querySelectorAll function

Trying to select all the div elements within another div using document.querySelectorAll. Interestingly, when setting the height to 1000 in the JS, the browser's scrollbar adjusts accordingly (the balloons do not change size). What could I be doing incorrectly?

'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>

Just in the testing phase to ensure everything functions properly.

Answer №1

It appears that the selector you used targeted the incorrect div. If you intend to increase the size of the ball, you should be selecting balloon-1 and balloon-2 instead of their parent element 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>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

AngularJS enables seamless two-way data binding with DropDownList in the Model-View-Controller (M

As a beginner in AngularJS, I am currently experimenting with implementing 2-way data binding for the Gender Dropdown menu similar to what I have done with textboxes. Below is a snippet of code for the dropdown control: <div class="form-group"> ...

Display only the relevant search results using ng-show in AngularJS

By utilizing the code below, I am able to filter results where all entries are displayed on the page: <body ng-app=""> <div ng-init="friends = [{name:'John', phone:'555-1276'}, {name: ...

The functionality of window.localStorage.removeItem seems to be malfunctioning when used within an $http

Currently, I am sending a post request to my web service and upon successful completion, I am attempting to remove a token from local storage. Here is the code snippet: $http.post("MyService/MyAction").success(function (res) { if ( ...

Creating a randomly generated array within a Reactjs application

Every time a user clicks a button in reactjs, I want to create a random array of a specific size. The code for generating the array looks like this: const generateArray = (arraySize: number): number[] => { return [...Array(arraySize)].map(() => ~~( ...

Bigcommerce encounters a 401 error during the payment processing, triggered by API with error code 10001

I recently started working on integrating the Bigcommerce payment API and I am facing issues with solving the 401 unauthorized error. Below is a sample of the data that I have tried: { "payment": { "instrument": {}, "payment_method_id": "cod", "amoun ...

What is the best approach to extracting tightly-coupled code and converting it into an external library?

I have a question regarding paradigms that I would like to address, and if this is not the appropriate platform, please guide me to the right place. Your recommendations are most welcome :) Currently, I am tasked with extracting a significant piece of fun ...

What could be causing the error where axios.get is not functioning properly?

Recently, I embarked on a journey to familiarize myself with working with packages and npm. My first step was to import axios for a simple http request. Initially, I set up the project using npm init successfully. However, I encountered my first roadbloc ...

Angular.js Form Submission Results in Error 405: POST Method is Not Permitted

Every time I attempt to submit my form, I come across a 405 error. Here is the code snippet from my controller: 'use strict'; angular. module('myApp'). component('zipPopup', { templateUrl: 'zip-popup/zip ...

An issue with the image filter function in JavaScript

I am currently working on a simple application that applies image filters to images. Below is the code I have written for this purpose. class ImageUtil { static getCanvas(width, height) { var canvas = document.querySelector("canvas"); canvas.widt ...

Angular: Clicking on a component triggers the reinitialization of all instances of that particular component

Imagine a page filled with project cards, each equipped with a favorite button. Clicking the button will mark the project as a favorite and change the icon accordingly. The issue arises when clicking on the favorite button causes all project cards to rese ...

Tips for updating a URL using data obtained from a JSON response

As I loop through an array from JSON, I extract all the necessary information. For example, if I have cards for blog posts that include the title, short description, published date, and URL. When clicking on a card, it redirects to a corresponding page ba ...

When the button onClick event is not functioning as expected in NextJS with TypeScript

After creating a login page with a button to sign in and hit an API, I encountered an issue where clicking the button does not trigger any action. I have checked the console log and no errors or responses are showing up. Could there be a mistake in my code ...

Messages are not being received despite no errors occurring in the PHP form

I am facing a challenge with a PHP script that is supposed to send a form, but it keeps saying the email has been sent while nothing actually shows up. Do you have any insights on what might be causing this issue? Also, there's nothing in the spam fol ...

What steps should I take to create a slider using my image gallery?

I have a unique photo gallery setup that I'm struggling with: As I keep adding photos, the cards in my gallery get smaller and smaller! What I really want is to show only 4 photos at a time and hide the rest, creating a sliding effect. I attempted ad ...

The functionality of clicking on a jQuery-generated element seems to be malfunctioning

When using Jquery, I am able to create an element and assign it the class .book: jQuery('<div/>', { name: "my name", class: 'book', text: 'Bookmark', }).appendTo('body'); I then wanted to add funct ...

The accumulation of keydown events in VueJs

Currently, I am developing a feature where a <textarea> field starts to fade out as soon as the user begins typing using v-on:keydown. However, if the user continues typing, the fading effect resets to keep the opacity: 1. Unexpectedly, the behavior ...

Tips for sending PHP variables together with a Typeahead variable

I have simplified this code as much as possible. I have a typeahead variable that is functioning correctly. However, I also need to pass two unrelated variables $php_var1 and $php_var2 along with the typeahead variable. These PHP variables are initialized ...

"Learn how to capture the complete URL and seamlessly transfer it to another JavaScript page using Node.js and Express.js

Is there a way to access the token variable in another page (api.js)? I need to use it in my index.js. var express = require('express'); var router = express.Router(); router.get('/', function(req, res ...

What is the best way to trigger a localstorage change event using Vue.js?

I'm currently facing an issue with my Vue app related to updating user information stored in localStorage. I've implemented a solution using websockets in App.vue within the mounted function, as shown below: window.Echo.channel("user." ...

Incorporate JavaScript values into an HTML form to submit them to PHP

How can I successfully POST the values of 'vkey' and 'gene+varient' when submitting a form in HTML? The values are retrieved using JS code and displayed correctly on the form, but are not being sent upon submission. <form action="ac ...