create two divs at once, unfortunately does not work at all and returns an error that says:
document.createElement(...) is not iterable
Is there a better way of creating more than one divs as the same time and assigning them to a different variables?
createElement creates only 1 element at once, just call it twice, one for each variable
How if I want to create hundreds of divs, is it possible to loop it?
In that case, just loop
May you please show me how to do so?
First you need to determine the amount of divs you need, you already know that?
Let's take 50 as an example, let's make 50 divs
const divs = []; for (let i = 0; i < 50; i++) divs[i] = document.createElement('div');
This is a verbose way of doing it, you could try also with more abstraction const divs = Array.from({ length: 50 }, () => document.createElement('div'));
It seems like this is the best hence few lines makes all divs
be careful with polyfill
Обсуждают сегодня