The DOM is like a toolkit for programmers to interact with and change the structure and content of HTML and XML documents. The DOM provides a structured and hierarchical representation of webpages, making it user-friendly and facilitating easier navigation and manipulation for both programmers and users.
With the DOM, you can quickly edit and grab HTML elements like tags, IDs, classes, and attributes by utilizing specific commands made available by the Document object.
Why DOM is required?
HTML DOM (Document Object Model)
When a web page loads, the browser generates a Document Object Model (DOM) of the page.
This HTML DOM model is built as a tree of objects:
Methods of Document Object:
The following DOM functions are useful:
- write(“string”): Writes a string to the document.
- getElementById(): Gets an element using its ID.
- getElementsByName(): Returns a list of all elements containing a specific name.
- getElementsByTagName(): Collects every element that has a particular tag name.
- getElementsByClassName(): Returns all elements that belong to a specific class.