How to use querySelectorAll to get direct children

56 views Asked by At

I know you can do this:

var sel = document.querySelectorAll(".list > a");

but what if you have a selection already and you want to get every direct child?

var list = document.querySelector(".list"); //say you can't change this line
var sel = list.querySelector("& > a"); //sass selector doesn't work

I know this can be done by checking on the childNodes list... but if querySelectorAll could be used, it would be much easier. I tried using ("& > a") and only ("> a") and didn't work... Got any ideas?

0

There are 0 answers