The Document object is the primary object of DOM. It holds the entire document through its properties and methods. This is accessed through JavaScript as document or window.document.
Key Properties/Methods of Document Object
documentElement: This property is the root element of the document.Html element is the root element in the case of HTML/XHTML documents.
getElementById(elementID): This is the most commonly used method in JavaScript. This method searches the entire document to find the element mentioned in the elementID attribute. If found, it returns that element.
getElementsByTagName(tagName): This method returns a collection of nodes (array) of all the elements in the Document object that match the tagName attribute.
createElement(element): This method creates a new element in the Document object with the element mentioned in the attribute element. For example, document.createElement(“div”); creates a div element. This element does not appear in the document until it has been added with the appendChild or insertBefore methods in the document.
createTextNode(textNode): This method creates a text node mentioned in the attribute textNode in the Document object. This element does not appear in the document until it has been added with the appendChild or insertBefore methods in the document.
Key Methods of the Element Object
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.
Document Object in ASP.Net JavaScript
Hot on Web: