As the name suggests, in this article we talk about DOM stands for Document object model (DOM). In DOM we discuss it’s properties and programmatical methods that are used for manipulating the document.
Introduction Document Object Model | What is a DOM
- In this dom tutorial, DOM or document object model is an application programming interface (API) for HTML and XML (Xtensible Markup Language) documents.
- It’s a structure called logical structure because they have no relations between objects.
- With DOM we have easy access and manipulate the HTML tags, IDs, classes, attributes or properties using predefined DOM methods or functions.
Structure of the Document Object Model
As the above discussion, the DOM has a logical structure that looks like a tree structure. We prove that statement using a Form a DOM example where we apply DOM methods.
Image Reference: https://www.geeksforgeeks.org
In the above picture, the properties of document objects are accessed by the document object method.
- Window Object: Window object is always on the top of the hierarchy.
- Document Object: When HTML is loaded on a window it becomes a document object.
- Link Object: Link objects represents by
linktags in HTML.
- Form Object: Form objects defined by
Formtag in HTML.
- Anchor Objects: It represents
<a href=" ">tag.
- Form Elements: Form can have many control elements like textarea, checkboxes, radio buttons, etc.
DOM Object Methods
- document.write(“string”): writes the given string on the document
- document.getElementById(): returns the element having the given id value.
- document. getElementsByName(): returns all the elements having the given name value.
- document.getElementsByTagName(): returns all the elements having the given tag name.
- document.getElementsByClassName(): returns all the elements having the given class name.
Code Example of DOM
See the Pen DOM (Document Object Model) by Bikash Panda (@phpcodertech) on CodePen.
8 Replies to “DOM | Document Object Model”