querySelectorAll(); !!

k so i have a div with the id "gridContainer" and then i have 100 divs inside of it each having the same "box" class now i want to get all those 100 divs and store em inside an array.. so i used
let box = document.querySelectorAll("box");
let box = document.querySelectorAll("box");
but when i tey to access an individual via console.log(box[10]); is shows undefined.. why and how would I store all the divs inside an array
6 Replies
glutonium
glutoniumā€¢16mo ago
here's the codepen
Jochem
Jochemā€¢16mo ago
querySelectorAll takes a CSS selector rule, not just a classname. You need to select for ".box" not "box"
glutonium
glutoniumā€¢16mo ago
oooh..okeey okeey.. didn't know that .. and tnx it worked ā¤ļø appreciate it
Jochem
Jochemā€¢16mo ago
no worries, glad to help šŸ™‚ it's not restricted to classes btw, afaik any valid css selector for that browser is also a valid value for querySelector and querySelectorAll so you can do some pretty cool stuff
glutonium
glutoniumā€¢16mo ago
gotcha