DEV Community

Discussion on: How to find a child (not direct child) of a specific element by Id(parent Id)?

Collapse
 
rehmatfalcon profile image
Kushal Niroula

You could get the element with the id and then use querySelector on it.

For example,

const parentElm = document.querySelector("#abc-1");
const childElm = parentElm.querySelector(".my-class"); 
Enter fullscreen mode Exit fullscreen mode

Of course you should always check if parentElm exists or not.

You could also use nested selector for the same.

const childElm = document.querySelector("#abc-1 .my-class");
Enter fullscreen mode Exit fullscreen mode