0

If I put document.querySelector inside a loop:

for (let i=0; i<5; i++)

and I want the querySelector to get the element by id "data1" if i=1, "data2" if i=2 and so on. How can I do this?

I have tried something like this but obviously it didn't work

for (let i=0; i<5; i++) { document.querySelector("#data${i}"); }

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
vnnz13
  • 1

0 Answers0