Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
childElementCount
Collapse the table of content
Expand the table of content

childElementCount property

Retrieves the number of immediate child nodes of the current element or a zero if the element does not contain any child nodes. IElementTraversal::childElementCount does not return all child nodes, only child nodes that are IHTMLDOMNode::nodeType =1, or element nodes.

Internet Explorer 9

 

Syntax

HRESULT value = object.get_childElementCount(* p);

Property values

Type: long

The number of child elements.

Standards information

Remarks

The IElementTraversal::childElementCount property only returns immediate children of the current node. It does not count descendent children of the immediate children.

Examples

This example shows how to use IElementTraversal::childElementCount to get the number of immediate children of a div tag. Be aware that because decendent children of the the div tag "divWithChildren" are ignored.


<!DOCTYPE html>
<html>
<head>
        <title>childElementCount example</title>
    <script>
        function GetCount () {
            var testArea = document.getElementById ("testArea");
            var childCount = 0;
                childCount = testArea.childElementCount;
            alert ("The number of child elements is " + childCount);
        }
    </script> 
</head>
<body>
    <div id="testArea" >
    <p>This is the test area, which contains several children.</p>
        <div id="divWithChildren">
            <div>a descendant child of a div</div>
            <div>also a descendent child of a div</div>
        </div>
        <p>A paragraph tag to consider.</p>
        <input type="text" size="80" value="And a text box as well"/> 
    </div>
    <p><input type="button" value="Get the number child elements in our test" name="abutton"  onclick="GetCount ();" /> </p>
    
</body> 
</html> 

 

 

Community Additions

ADD
Show:
© 2015 Microsoft