WebMasterCampus
WEB DEVELOPER Resources

Javascript Document QuerySelectorAll to Find All Children Elements

Learn how to use Javascript Document QuerySelectorAll to Find All Children Elements


Javascript QuerySelectorAll to Find All Children Elements

The Document method querySelectorAll() returns a static (not live) NodeList representing a list of the document’s elements that match the specified group of selectors.

Syntax


document.querySelectorAll(CSS selectors)

Example QuerySelectorAll


<h1>Javascript Document QuerySelectorAll to Find All Children Elements</h1>

    <div id="wrapper">
        <p>This is a paragraph</p>
        <div>This is first Div</div>
        <div>This is second div</div>
    </div>

    <script>
        var wrapper_children = document.querySelectorAll("#wrapper>*");

        for (i=0; i < wrapper_children.length; i++){
            console.log(wrapper_children[i].tagName);
            console.log(wrapper_children[i].textContent);
            console.log(wrapper_children[i].outerHTML);
            console.log(wrapper_children[i].parentElement.tagName);
            console.log("------------------------");
        }        

    </script>
Created with love and passion.