
What is the DOM in JavaScript? A Comprehensive Guide
☰Fullscreen
Table of Content:
- The HTML DOM is an accepted guideline for how to access, update, add or remove HTML elements.
- A Structure representation of an HTML document is provided by DOM.
- An HTML document is completely built using objects. DOM represents it in an objected-oriented way which can be manipulated using scripting languages like javascript.
- All the objects in the HTML document are hierarchically connected to one another. The
document
object forms the root of all objects.
DOM can do many things
- JavaScript can change all the HTML elements in the page
- JavaScript can change all the HTML attributes in the page
- JavaScript can change all the CSS styles in the page
- JavaScript can remove existing HTML elements and attributes
- JavaScript can add new HTML elements and attributes
- JavaScript can react to all existing HTML events in the page
- JavaScript can create new HTML events in the page
Example: Script file
let val; val = document; val = document.all val = document.all[2] val = document.length; val = document.head; val = document.body; val = document.doctype; val = document.domain; val = document.URL; val = document.characterSet; val = document.contentType;
// we can access forms val = document.forms; val = document.forms[0]; val = document.forms[0].id; val = document.forms[0].method; val = document.forms[0].action;
// we can access links val = document.links; val = document.links[0]; val = document.links[0].id; val = document.links[0].className; val = document.links[0].classList; val = document.links[0].classList[0];
// we can access images val = document.images;
// we can access scripts val = document.scripts; val = document.scripts[2]; val = document.scripts[2].getAttribute('src');
- Question 1: How to Hide Div in JavaScript?
- Question 2: How to Change Border Color of Div in JavaScript?
- Question 3: How to Change Border Radius of Div in JavaScript?
- Question 4: How to Change Border Width of Div in JavaScript?
- Question 5: How to Change Bottom Border of Div in JavaScript?
- Question 6: How to Change Border Style of Div in JavaScript?
- Question 7: How to Change Font Color of Div in JavaScript?
- Question 8: How to Change Font Family of Div in JavaScript?
- Question 9: How to Change Font Weight of Div in JavaScript?
- Question 10: How to Change Height of Div in JavaScript?
- Question 11: How to Change Left Border of Div in JavaScript?
- Question 12: How to Change Margin of Div in JavaScript?
- Question 13: How to Change Opacity of Div in JavaScript?
- Question 14: How to Change Padding of Div in JavaScript?
- Question 15: How to Change Right Border of Div in JavaScript?
- Question 16: How to Change Padding of Div in JavaScript?
- Question 17: How to Change Text in Div to Bold in JavaScript?
- Question 18: How to Change Top Border of Div in JavaScript?
- Question 19: How to Change Text in Div to Italic in JavaScript?
- Question 20: How to Change Width of Div in JavaScript?
- Question 21: How to Change the Background Color of Div in JavaScript?
- Question 22: How to Change the Border of Div in JavaScript?
- Question 23: How to Clear Inline Style of Div in JavaScript?
- Question 24: How to Hide Div in JavaScript?
- Question 25: How to Insert Element in Document after Specific Div Element using JavaScript?
- Question 26: How to Underline Text in Div in JavaScript?
- Question 27: How to get Attributes of Div Element in JavaScript?
Related Questions
- Assignment 1: How to select all li at once using JavaScript