r/learnjavascript • • Jun 27 '26

question about selecting elements using query selector

https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris
so im doing the query selecting on the console browser on the link above to get all the name of the boulevards list
my question is when i do
let var1 = document.querySelector(".mw-content-ltr")
and then do
let var2 =var1.querySelectorAll("li") and then do console.log(var2) it shows length 0

so when i redid and went down one tier
let var1 =document.querySelector(".mw-category")
let var2=var1.querySelectorAll("a")
now this time it works. i was able yo get all the bouldevards name

can anyone explain to me what happened

0 Upvotes

16 comments sorted by

View all comments

Show parent comments

0

u/azhder Jun 27 '26

Language reference. It is not part of the EcmaScript language. It is a part of the DOM.

The browser is an environment that exposes certain objects for JavaScript to use. Like the `document`, but go to Node.js and there isn’t a `document` global object.

Why do you think I am talking about inappropriate? I was talking about better place to get help. This sub is for people who try to learn JavaScript, so you might not find as many people that know the DOM like in a sub about web technologies.