Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Elements are nothing but the tags in a HTML document. All of these tags create an element in the Document object. For example, the <p> tag creates a p element in the Document object. All the methods mentioned earlier for the Node object are applicable to the Element object. Some of the other key methods are listed in Table 4.6.
| Property/Method | Description |
|---|---|
| getAttribute(attributeName) | This method returns an element’s attribute, attributeName, in the form of a string. |
| setAttribute(attributeName) | This method sets an element’s attribute, attributeName. |
| getElementsByTagName(tagName) | This method returns a collection of nodes (array) of all the elements that are the descendants of an Element object that match the tagName attribute. This method is quite similar to the Document object’s methods except that this fetches all the elements under this element. |