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
glutoniumOPā€¢2y ago
here's the codepen
Jochem
Jochemā€¢2y ago
querySelectorAll takes a CSS selector rule, not just a classname. You need to select for ".box" not "box"
glutonium
glutoniumOPā€¢2y ago
oooh..okeey okeey.. didn't know that .. and tnx it worked ā¤ļø appreciate it
Jochem
Jochemā€¢2y 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
glutoniumOPā€¢2y ago
gotcha
Want results from more Discord servers?
Add your server