DEV Community

Raja B
Raja B

Posted on

DOM

The DOM in JavaScript means the Document Object Model. It is the browser’s tree-like representation of an HTML page, and JavaScript uses it to read, change, add, or remove elements on the page

DOM

Simple idea

Think of HTML as the page structure, and the DOM as the live version of that page inside the browser. JavaScript talks to the DOM to make websites interactive, such as changing text, styles, or reacting to clicks

<p id="demo">Hello</p>
<button onclick="changeText()">Click</button>

<script>
function changeText() {
  document.getElementById("demo").innerHTML = "Hi Raja!";
}
</script>
Enter fullscreen mode Exit fullscreen mode

Here, document.getElementById("demo") finds the paragraph, and innerHTML changes its content

What you can do with DOM

  • Select elements

  • Change text or HTML

  • Update CSS styles

  • Add or remove elements

  • Handle events like click, input, or submit

Reference:

Top comments (1)

Collapse
 
karthick_07 profile image
Karthick (k)

Highly informative