DEV Community

Divya Bharathi
Divya Bharathi

Posted on

What is DOM in JavaScript?

Hello everyone! Today we discuss about DOM in javascript.DOM(Document Object Model) it is used to interact with the run time programs for creating some dynamic changes in the browser.Javascript interface with HTML and CSS using the DOM.

- EVENTS:

DOM events in JavaScript are actions or occurrences that happen within the browser window and can be detected and responded to using JavaScript. These events allow for dynamic and interactive web pages by enabling scripts to react to user interactions or changes in the document's state.
For examples:onclick,onchange,onscroll,etc...

Why we use id and class? and How could it declared?
Id is used to call a unique or one element and it is declared as **document.getElementById("abc")**.
Class is used to call the multiple elements and it is declared as **document.getElementByClassName("xyz")**.

Sample example for DOM

 <body>
    <h1 id="heading">WEBSITE</h1>
    <h1 id="Name">ABC</h1>
    <button onclick="changeText()">changeText</button>

    <script>
        function changeText(){
            const element = document.getElementById("Name")
            element.innerHTML="Divyabharathi";
            element.style.color="Blue";
        }
    </script>
</body>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)