You are here: Reference > JavaScript > client-side > selection and ranges > methods > selectAllChildren (selectionRange)

selectAllChildren method (selectionRange)

Browser support:
9
Cancels the current selection and selects the child elements of the specified element.
Note: The selectionRange object and its selectAllChildren method are supported in Internet Explorer from version 9.

Syntax:

object.selectAllChildren (element);
You can find the related objects in the Supported by objects section below.

Parameters:

element
Required. Reference to the element whose children need to be selected.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the selectAllChildren method:
<head>
    <script type="text/javascript">
        function SelectContents () {
            var elemToSelect = document.getElementById ("myDiv");
            if (window.getSelection) {  // all browsers, except IE before version 9
                var selection = window.getSelection ();
                selection.selectAllChildren (elemToSelect);
            } else {                    // Internet Explorer before version 9
                var range = document.body.createTextRange ();
                range.moveToElementText (elemToSelect);
                range.select ();
            }
        }
    </script>
</head>
<body>
    <button onclick="SelectContents ();">Select the contents of the following field!</button>
    <div id="myDiv">The <b>field</b> to <i>select</i>.</div>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content