Reputation: 1115
I'm learning how to appending DOM nodes with Javascript and have a little clarification question. Here's an example:
<html>
<head>
</head>
<body>
</body>
</html>
document.childNodes[0]
So here, you would get the <head>
node because it is the first child after the <html>
tag. My question is can I always consider "document" to be the equivalent of the <html>
tag or root node?
Upvotes: 2
Views: 78
Reputation: 106385
I'd recommend studying the W3C DOM spec as well: even if some parts of it won't mean much to you, it might save you a plenty of time and efforts later. )
That's what's said about document
here:
The Document interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
Upvotes: 1
Reputation: 707328
document.childNodes[0]
is the <!DOCTYPE>
node when I try it (though not sure if that's always the case).
document.documentElement
is the <html>
tag.
document.body
is the <body>
tag.
Upvotes: 0
Reputation: 14304
Root node for html is ... html, which can be get via document.documentElement
I'm not sure, it is supported in all modern browsers, though.
Upvotes: 0