implement lastElementChild

This commit is contained in:
Vincent Sanders 2012-11-18 12:38:07 +00:00
parent b1ca83ad8c
commit bec8711528
4 changed files with 44 additions and 1 deletions

View File

@ -89,6 +89,37 @@ getter firstElementChild %{
%}
getter lastElementChild %{
dom_node *element;
dom_exception exc;
dom_node_type node_type;
dom_node *sib_node;
exc = dom_node_get_last_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)) {
/* found it */
jsret = jsapi_new_HTMLElement(cx,
NULL,
NULL,
(dom_element *)element,
private->htmlc);
break;
}
exc = dom_node_get_previous_sibling(element, &sib_node);
dom_node_unref(element);
if (exc == DOM_NO_ERR) {
element = sib_node;
} else {
element = NULL;
}
}
%}
getter previousElementSibling %{

View File

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

View File

@ -24,7 +24,8 @@
<h2>DOM tests</h2>
<h3>Reference method tests</h3>
<ul>
<li><a href="doc-dom1.html">firstElementChild</a></li>
<li><a href="dom-element-firstElementChild.html">firstElementChild</a></li>
<li><a href="dom-element-lastElementChild.html">lastElementChild</a></li>
<li><a href="doc-dom2.html">getElementById</a></li>
<li><a href="dom-getElementsByTagName.html">getElementsByTagName</a></li>