JavaScript JavaScript and the DOM Getting a Handle on the DOM Using CSS Queries to Select Page Elements

guram dgebuadze
guram dgebuadze
Front End Web Development Techdegree Student 4,121 Points

querySelectorAll(' '); While writing this we need css selectors and why do we need > to refer to the child of the elemen

for example querySelectorAll(' #nav > p'); > why do we use this thing in js to refer to child of the nav id, while we don't use it when we are writing in css?

2 Answers

Brendan Whiting
MOD
Brendan Whiting
Front End Web Development Treehouse Moderator 84,142 Points

You can use it in CSS as well. > is for a direct child, but just a space is for any descendant.

This SO thread might help.