开发者

Doesnt attribute nodes count as children in DOM2?

Doesnt attribute nodes count as children in DOM?

My page here is like this 5 children in the body: text > h1 > text > div > text > //end of 5 children But doesnt the attributnodes count? Shouldnt the childNodes property return an array of all types of nodes? With text > attribute > text > h1 > attribut > text > div > attribut > text > p //etc...

I have this page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>DOM testing</title>
        <script src="scripts/domTesting3.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body bgcolor="#cccccc">
        <h1 id="test">Test</h1>
        <div id="content">
            <p>Examining the DOM2 Core and DOM2 HTML Recommendations</p>
            <h2>Browsers</h2>
            <ul id="browserList">
                <li id="chromeListItem">
                    <a href="http://www.google.com/chrome/ "title="Get Chrome" id="chrome">Chrome</a>
                </li> 
                <li id="firefoxListItem">
                    <a href="http://www.getfirefox.com/"title="Get Firefox" id="firefox">Firefox 5.0</a>
                </li> 
                <li>
                    <a href="http://www.microsoft.com/windows/ie/downloads/" title="Get Microsoft Internet Explorer" id="msie">Microsoft Internet Explorer 9</a>
                </li> 
                <li>
                    <a href="http://www.apple.com/macosx/features/safari/" title="Check out Safari" id="safari">Safari</a>
                </li>
                <li>
                    <a href="http://www.opera.com/download/" title="Get Opera" id="opera">Opera 9</a>
                </li> 
            </ul>
        </div>
    </body>
</html>

with this script:

function domTest() {
    var le = document.body.childNodes.length;
    alert(le);//alerts 5 children where are attribut no开发者_运维百科des?
    for(i = 0; i < le; i++) {
        alert(document.body.childNodes[i].nodeType);
        alert(document.body.childNodes[i].nodeName);
        alert(document.body.childNodes[i].nodeValue);
    }   
}

window.onload = domTest;


Attr objects inherit the Node interface, but since they are not actually child nodes of the element they describe, the DOM does not consider them part of the document tree. Thus, the Node attributes parentNode, previousSibling, and nextSibling have a null value for Attr objects

From the Attr interface description of DOM Level 2 Core.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜