DOM in JavaScript

Muiliyu Sodiq Akintomide
2 min readNov 18, 2023

--

DOM is an acronym for Document Object Model. This term can simply be defined as an interface that allows scripts to dynamically manipulate the content, structure, and style of web documents. in simpler terms, DOM provides a way for javascripts to interact with HTML or XML documents which makes it possible to modify the contents of a web page in real time.

For better understanding and visualisation, let’s see the code snippet:

HTML code

We have the output of the code above to produce the below

In this example, the JavaScript code can manipulate the content of the page using the DOM. For instance, to change the text content of the heading element, the following JavaScript code can be used:

Javascript code to manipute the the HTML code

if the button that says “Click me” in the output above is called, the function “action” is called. clicking the button will give this output:

output after clicking on the button

In conclusion,the Document Object Model can be used by developers to access, manipulate, and update the content of webpages, providing a dynamic and responsive user experience. Understanding the DOM is fundamental for anyone working with front-end web development and is a key aspect of creating modern, interactive web applications.

--

--