What are the main functions of HTML DOM ? Last Updated : 10 Apr, 2023 Comments Improve Suggest changes Like Article Like Report DOM or Document Object Model is an API(Application Programming Interface) that represents the HTML document in the form of the Tree structure such that programs can access and change the style and structure of the HTML document. The DOM object is automatically created by the web browser itself upon opening an HTML web page. The HTML DOM contains three parts: Document: This is the HTML Document that we createObject: All the Elements and Attributes present in the HTML document come under Objects (Ex: <h1> <p> <img> etc)Model: The Tree structure of the elements is called a Model. Structural Representation of HTML DOM: HTML Code: Consider a simple HTML code as follows. HTML <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h2>Welcome To GFG</h2> <p>Default code has been loaded into the Editor.</p> </body> </html> The HTML DOM created upon opening this web page by the web browser is as follows: HTML DOM REPRESENTATION Main Functions of HTML DOM The functions of HTML DOM are as follows: DOM API can be used to access and modify the data present in the HTML document using JavaScript language. We can manipulate the following using the DOM API: HTML elements, attributes, and data present between the tags and CSS Styles. DOM enables the programmers to create web pages that use dynamic HTML i.e. Those websites that get updated without refreshing the website. It also enables the programmers to develop web pages or websites that are user-customizable i.e. The user can himself/herself can edit the HTML elements on the fly. (For Ex: changing the color of the web page or the button) It functions as a bridge that makes the webpage dynamic using the JavaScript language. Hence to make the website more interactive and dynamic, DOM provides various methods to access the elements and attributes using JavaScript. Some of the methods available are as followsgetElementById() : This method is used to access the element present in the html document using it's unique ID.innerHTML: This is used to change the content present between the elements.addEventListener(): This method is used to get hold of the event object if an event is triggered (like mouse clicked)appendChild(): This method is used to append an element in the document. Let's see an example of HTML DOM: In the below HTML code , we get hold of the data given in input text area element using document.getElementById().value and change the text of using document.write(). Hence these are the main functions of HTML DOM that help in accessing, modifying the data present in HTML Filename: index.html html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content= "width=device-width, initial-scale=1.0"> </head> <body> <h1 style="color: green; text-align: center;"> GeeksforGeeks </h1> <form> <div class="wrapper" style="text-align: center;"> Enter your name: <input type="text" id="t1" /> <br><br> <input type="submit" style="position: absolute;" onclick="func()" /> </div> </form> <script> function func() { var name = document.getElementById("t1").value; document.write("Hello" + name + ",this text is printed using HTML DOM "); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article What are the main functions of HTML DOM ? phanitejau Follow Improve Article Tags : HTML HTML-DOM HTML-Questions Similar Reads What are empty elements in HTML ? An empty element is a component that doesn't have any embedded elements or text elements. Empty tags contain only the opening tag but they perform some action in the webpage. For example, <br> tag is an empty tag. In this article, we will see the empty tags in HTML & we will also focus on 3 min read What are logical tags in HTML ? Logical tags are used to tell the browser what kind of text is written inside the tags. They are different from physical tags because physical tags are used to decide the appearance of the text and do not provide any information about the text. Logical tags are used to indicate to the visually impai 5 min read What are the various formatting tags available in HTML ? As we know, HTML provides many predefined elements that are used to change the formatting of text. The formatting can be used to set the text styles (like â bold, italic, or emphasized, etc.), highlight the text, make text superscript and subscript, etc. In this article, we will discuss different fo 3 min read Explain the importance of Doctype in HTML ? Doctype in HTML: HTML Doctype is most often written at the very first element of the entire HTML document. It remains wrapped inside angle brackets but it is not a tag. It is a statement or declaration. Doctype stands for Document Type. It is a statement to declare the type of the document. With the 3 min read Elements that are used in head section of HTML page The <head> element is like a container for metadata i.e. data about data and it also lies between the <html> tag and the <body> tag. Metadata is the data about the HTML document and is not displayed on the webpage. It defines the document title, style, script, and other meta inform 3 min read What is usually included in the header of an HTML document ? The <header> is a tag introduced in HTML5. In this article, we are going to discuss the use cases of header tags and what is usually included in the header of an HTML document. The <head> section in HTML usually includes the document's title (<title>), which appears in the browser' 3 min read Is HTML elements are same as tags or not ? HTML elements and tags are a lot different. Let's see what HTML elements and Tags actually are and their differences. The below image tells about HTML Elements and HTML Tags. HTML Tags: The starting and ending point parts of an HTML document are HTML Tags, which start with < (less than) and end w 2 min read What is HTML DOM ? HTML DOM stands for the Document Object Model is a tree-like structure that offers dynamic interaction and manipulation of the content, structure, and style of an HTML document. It is an interface for web documents. Based on user activity The HTML DOM offers to create interactive web pages where ele 4 min read HTML Course | Structure of an HTML Document HTML (Hypertext Markup Language) is used in over 95% of websites and is the foundation of all web pages. It provides the basic structure and content layout. For beginners in web development, learning HTML is the essential first step. Structure of an HTML DocumentWhat is an HTML Document?HTML is a ma 4 min read Describe the void elements in HTML Most of the HTML elements are surrounded by start and end tags to specify the starting and end of the element. There is a special group of elements that only have start tags and does not contain any content within it, these elements are called void elements. Void elements doesn't have ending tags an 3 min read Like