You can also use:
Code:
document.documentElement
for <html>
and:
for <body>
And, if you're not interested in text nodes:
Code:
document.getElementsByTagName('*')
Will get you a node list of all of the tags in the document. Similarly you can go after specific tags:
Code:
document.getElementsByTagName('head')[0]
will get you the head, Or:
Code:
document.getElementsByTagName('div')
Will get you all of the divs, which you could then iterate over to find the one you want. Or if you already know, refer to it by its index, ex:
Code:
document.getElementsByTagName('div')[5]
Which would be the 6th - if it exists.
It really all depends upon what you're after, and how best to get a reference to it. Sometimes there are multiple ways. Well almost always, but sometimes two or more of these methods will be just as good as the other.
Bookmarks