Generating a series of DIV elements using the DOM and attaching them to the primary DIV

I am attempting to dynamically create 121 divs using the DOM and then add them to the .container div

const container= document.querySelector('.container');
        const divNumber= 121;
        for (let i= 0; i<= 121; i++){
            const divs= document.createElement('div');
            divs.classList.add('items');
            container.appendChild(divs);
        }
.container {
            display: grid;
            grid-template-columns: auto auto auto auto auto auto auto auto auto auto auto;
        }
        .items {
            border: 1px solid black;
            margin: 0px;
        }
<div class='container'></div>

There doesn't appear to be any changes on the webpage. How can I generate a group of 11 by 11, totaling 121 divs with the use of the DOM and insert them into the parent div, which is .container in this instance?

Answer №1

Implement the grid-gap property to ensure all grids are overlapping.

const container = document.querySelector('.container');
const divNumber = 121;
for (let i = 0; i < 121; i++) {
  const divs = document.createElement('div');
  divs.classList.add('items');
  divs.innerHTML = i + 1
  container.appendChild(divs);
}
.container {
  display: grid;
  grid-template-columns: repeat(11,1fr);
  grid-gap: 20px;
}

.items {
  border: 1px solid black;
  margin: 0px;
  padding: 5px;
  color: green;
}
<div class='container'></div>

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

Catalog of items in Mustache

I am currently working on generating HTML content using the mustache template engine. However, I have encountered an issue when trying to render a list of objects. Below is an example of my object: var Prod={ "Object1": { "name": "name1", "cat ...

Implementing JavaScript Functions to Trigger Control Key and Plus/Minus Events

In my project, I have a unique set of selectors called A+. By clicking on the A+ button, it has been programmed to initiate the control plus event. Similarly, within the same interface, I also have an A- button that activates the control minus event when ...

Adding a Header Image to the Top of All Pages with CSS

As I dive into the world of website creation, I've encountered a challenge that has me stumped. My goal is to have a banner displayed at the top of each webpage on my site, and I'm unsure if this can be achieved using CSS. While I've success ...

Ways to showcase a div exclusively on UC mini browser

I'm looking for help to create a script that will only display a div with the class "info-box" in UC Mini browser. This div should be hidden in all other browsers. Can someone assist me with this? <!doctype html> <html> <head> <m ...

How can the @blur event be added to the vue-bootstrap-typeahead in Nuxt/Vue application?

I am facing an issue where I want to trigger a function upon leaving an input field. The input in question is set up using vue-bootstrap-typeahead. Upon inspecting the DOM, I found that the structure of the input element looks like this: <div id="m ...

Navigating between various arrays

I'm struggling to create a basic slideshow using the JavaScript code below, but it doesn't seem to be functioning correctly. I have meticulously checked for any errors in spelling and made sure all elements are correctly linked to my HTML. JavaS ...

Scroll through a particular HTML element using jQuery animation

Can an object be animated from one position to another following a specific path? For instance, if moving from pos1 to pos2, and encountering a div with the class "no-ok" in the way, the object should avoid it and find the nearest div named OK either to th ...

A timer created using jQuery and JavaScript

Looking for a way to automatically transition between three div elements with a fade in/out effect every 8 seconds? Check out this simple code snippet I wrote: $(".link1").click(function () { $(".feature1").fadeIn(1000); $(".feature2").fadeOut(1000) ...

Fill in according to the options selected in the dropdown menu

Recently delving into the world of React, I encountered a design challenge that needs solving. My goal is to have a selection field with various choice values, each offering different sets of KPIs and UOMs. Depending on the chosen value, I should be able t ...

Creating Recursive Portals with three.js

I am working on developing a simple portal game using three.js, but I am facing a challenge with creating recursive portals. One solution I have considered is placing the camera on one portal and rendering its image as a texture on the other portal. While ...

Can you explain the reference point used in the `drawImage()` function on a canvas?

Here is an inquiry concerning the usage of the drawImage() function. var x = (i-j)*(img[0].height/2) + (ctx.canvas.width/2)-(img[0].width/2); var y = (i+j)*(img[0].height/4); abposx = x + offset_x; abposy = y + offset_y; ctx.drawImage ...

Are there any current implementations of the Media Capture API in use?

After delving into the details of the draft Device APIs, I am curious if there are any existing implementations of the Media Capture API. Ericsson has showcased a few demos but hasn't made the source code available yet. There is also a reported bug o ...

How can I modify the function inside the event listener in a React Functional Component?

I'm facing an issue where I need to utilize both a variable defined within a functional component and a part of the props of the functional component in the callback function of a mousemove eventlistener. Although I have the code below, it appears th ...

Tips for accessing an Element by its Id in Vue

I am trying to access an external Element in Vue by using the method getElementById(): new Vue({ el: "#vue", data: { helloElement: document.getElementById('hello') } }) <script src="https://cdnjs.cloudflare.com/ajax/libs/v ...

The Vuetify v-btn within the v-bottom-navigation remains in an active state even when it has not

I am encountering an issue with a button in the bottom navigation bar of my Vuetify application. I have set up several buttons as routes in Nuxtjs, which become active when the corresponding page is visited. However, there is a button in the bottom nav bar ...

What are some methods for applying border styles to the first and last row of a table using Material UI?

In my current project, I am utilizing the combination of Material UI and React Table. Recently, I was asked to implement an expandable row feature, which I successfully added. Once the user expands the row, we need to display additional table rows based on ...

How to turn off double tap zoom feature in Safari on iOS devices

As I work on developing my web browser game, I encountered an issue with Safari iOS where double tapping triggers a magnifying glass feature: https://i.sstatic.net/B2y2L.png I have been trying to disable this feature but so far, no luck. I attempted usin ...

Storing audio files in Firebase Cloud Database and displaying them in React js + Dealing with an infinite loop problem

Lately, I've been encountering a persistent issue that has proven to be quite challenging. Any assistance would be greatly appreciated. Thank you in advance. The objective is to create a form that allows for the easy addition of new documents to the ...

How to retrieve a value from PHP using Ajax?

I am struggling to implement ajax for adding a div to display an error message. Despite my efforts, I keep receiving null as the error message instead of the expected value. The occurrence of null is traced back to <?php echo json_encode($_SESSION[&ap ...

What is the best way to remove text messages from a channel that only allows images?

I have developed a Discord bot named YES with a specific text channel for images only. My goal is to program the bot to automatically delete any text messages in this channel and respond with "You cannot send text messages." However, I also want to create ...