There are other types not covered in the table, but these aren't used in HTML documents.
As we can see from the table, a code of 1 confirms that body is an element node.
We can also use the nodeName property to find the name of the element:
Note that the element name is returned in upper-case letters.
Legacy DOM Shortcut Methods
There are some methods from DOM Level 0 that can still be employed to access commonly
• document.body returns the body element of a web page, as we saw in the pre-
• document.images returns a node list of all the images contained in the docu-
• document.links returns a node list of all the <a> elements and <area> ele-
ments that have an href attribute.
• document.anchors returns a node list of all the <a> elements that have a
• document.forms returns a node list of all the forms in the document. This will
Warning: Array- like , but not an Array
Node lists are array-like objects, but they are not arrays. You can access
each item using index notation. For example, document.images
will return the first image in the node list of all the images in the document.
They also have a length property, which can be used to iterate through
every element using a for loop, like so:
Search WWH ::