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
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
here's the codepen
querySelectorAll
takes a CSS selector rule, not just a classname. You need to select for ".box"
not "box"
oooh..okeey okeey.. didn't know that .. and tnx it worked
ā¤ļø appreciate it
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 stuffgotcha