HTML | DOM selectAllChildren() Method

The selectAllChildren() method adds all the children of the specified node to the current selection.

Syntax:

selection.selectAllChildren( parentNode )

Parameters:

  • parentNode: The node whose children are to be selected.

Example: In this example, all the child elements of the parent div will get selected on button click using this method.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>GeeksforGeeks</title>
</head>
  
<body>
    <main>
        <h1>GeeksforGeeks</h1>
    </main>
  
    <div>
        <p>child 1</p>
        <p>child 2</p>
        <p>child 3</p>
    </div>
  
    <button onclick="select()">
        click
    </button>
  
    <script>
        const pNode = document
            .querySelector('div');
              
        function select() {
            window.getSelection()
                .selectAllChildren(pNode);
        };
    </script>
</body>
  
</html>

chevron_right


Output:



Click the button to select child node of parent div:

Supported Browsers: The browsers supported by selectAllChildren() method are listed below:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari
  • Internet Explorer.

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.