Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the direct child selector (>) to only select the immediate children of an element. For example, if you want to select all the

  • elements inside a
      element without selecting any nested
        elements, you can use the following code:

        const listItems = document.querySelectorAll("ul > li");
        

        This will only select the

      • elements that are direct children of
          elements and not any nested
            elements.