Document Object Model (DOM) in JavaScript
Each site resides within a browser window that can be viewed as an object.
A Document object represents the HTML document displayed in that window. The Document object has as many properties as other objects that allow access and editing of document content.
The way content content is accessed and edited is called Document Object Model , or DOM . Objects are organized according to hierarchical structure. This hierarchical structure applies to the organization of objects in a Web page.
- Window object - Highest level in structure. It is the furthest element in the object hierarchy.
- Document object - Each HTML document loaded into a window becomes a Document object. This object contains the content of the page.
- Form object - Everything in the tag . set the Form object.
- Form control object - The Form object contains all the elements defined for that object such as text fields, buttons, and text boxes.
Here is a simple hierarchical structure of some important objects:
The next section explains in detail the existing DOMs and describes how you can use them to access and edit document content.
Legacy DOM - This model was introduced in the earliest JavaScript versions. It is well supported by all browsers, but only allows access to certain parts of the document, such as Form, Image, Font elements.
W3C DOM - This model allows access and editing of all document content and is standardized by W3C. This model is supported by most modern browsers.
IE4 DOM - This model was introduced in Microsoft's version of IE 4. IE 5 and later versions include support for most of the basic features of the W3C DOM.
DOM compatibility
If you want to write a script with the flexibility to use either W3C DOM or IE 4 DOM depending on their availability, then you can use a Capability-testing approach (the ability to test ) that first checks for the existence of a method or attribute to decide whether or not the browser has the ability you want. For example:
if ( document . getElementById ) { // If the W3C method exists, use it } else if ( document . all ) { // If the all[] array exists, use it } else { // Otherwise use the legacy DOM }
According to Tutorialspoint
Previous lesson: Regular Expression and RegExp in JavaScript
Next article: Handling errors in JavaScript
You should read it
- Objects in JavaScript
- For ... loop in JavaScript
- String object in JavaScript
- Date object in JavaScript
- Multimedia (Multimedia) in JavaScript
- What is JavaScript?
- Print pages in JavaScript
- Object Number in JavaScript
- Syntax of JavaScript
- Learn about Collection of Record in JavaScript
- What is JavaScript? Can the Internet exist without JavaScript?
- How to turn on and turn off Javascript on Firefox, Chrome
Maybe you are interested
PowerPoint 2016: Arrange and group objects
Can I take photos of moving objects on a smartphone?
AI erases objects in footage in real time, making filming more 'leisurely'
Detecting an unusual object lurking in our Galaxy, possibly a black hole
PowerPoint 2016: Animate text and objects
Instructions for deleting objects in photos on iOS 18