implement childElementCount

This commit is contained in:
Vincent Sanders 2012-11-18 17:35:52 +00:00
parent 99d3633e03
commit fa9046fc97
3 changed files with 39 additions and 0 deletions

View File

@ -187,3 +187,30 @@ getter nextElementSibling %{
}
}
%}
getter childElementCount %{
dom_node *element;
dom_exception exc;
dom_node_type node_type;
dom_node *next_node;
exc = dom_node_get_first_child(private->node, &element);
if (exc != DOM_NO_ERR) {
return JS_FALSE;
}
while (element != NULL) {
exc = dom_node_get_node_type(element, &node_type);
if ((exc == DOM_NO_ERR) && (node_type == DOM_ELEMENT_NODE)) {
jsret += 1;
}
exc = dom_node_get_next_sibling(element, &next_node);
dom_node_unref(element);
if (exc == DOM_NO_ERR) {
element = next_node;
} else {
element = NULL;
}
}
%}

View File

@ -0,0 +1,11 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="tst.css">
<title>DOM childElementCount reference</title>
</head>
<body>
<h1>DOM childElementCount reference</h1>
<p><b>head.childElementCount:</b> <script>document.write(document.head.childElementCount);</script></p>
<p><b>body.childElementCount:</b> <script>document.write(document.body.childElementCount);</script></p>
</body>
</html>

View File

@ -27,6 +27,7 @@
<li><a href="dom-element-firstElementChild.html">firstElementChild</a></li>
<li><a href="dom-element-lastElementChild.html">lastElementChild</a></li>
<li><a href="dom-element-next_prev_ElementSibling.html">previousElementSibling nextElementSibling</a></li>
<li><a href="dom-element-childElementCount.html">childElementCount</a></li>
<li><a href="doc-dom2.html">getElementById</a></li>
<li><a href="dom-getElementsByTagName.html">getElementsByTagName</a></li>