This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

selectAllChildren

Summary

Adds all the children of the specified node to the selection. Previous selection is lost.

Method of dom/Selectiondom/Selection

Syntax

var result = selObj.selectAllChildren(/* see parameter list */);

Parameters

parentNode

Data-type
DOM Node

The object that receives the new selection.

Return Value

Returns an object of type NumberNumber

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Examples

In this example, your selection is replaced by all the elements of the DIV.

<!DOCTYPE html>
<head>
    <title>Select all children example</title>
    <script>
        function selectAllChildrenDemo () {
            var getNode = document.getElementById ("elementID");
            if (window.getSelection) {        // Internet Explorer 9
                var selection = window.getSelection ();
                selection.selectAllChildren (getNode);
            } else {                          // Workaround for Internet Explorer 8 & earlier
                var oRange = document.body.createTextRange ();
                oRange.moveToElementText (getNode);
                oRange.select ();
            }
        }
    </script>
</head>
<body>
    <button onclick="selectAllChildrenDemo ();">Select everything below</button>
    <div id="elementID">The <strong>selectAllChildren</strong> method replaces the current <em>selection</em> with the all the <strong>contents</strong> of the specified element (in this case a DIV).</div>
</body>
var footer = document.getElementById("footer");
window.getSelection().selectAllChildren(footer);
/* Everything inside the footer is now selected */

Notes

Remarks

Raises a WRONG_DOCUMENT_ERR DOMException if the parentNode is in another document.

Syntax

Standards information

Attributions