Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

The Element Object

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.

Table 4.6. Key Methods of the Element Object
Property/MethodDescription
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.



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial