HTML CSS JAVASCRIPT PYTHON JAVA

JavaScript DOM

The DOM (Document Object Model) is a programming interface for web pages. It represents the structure of an HTML document as objects that JavaScript can access and modify.

With the DOM, JavaScript can change HTML content, styles, and attributes dynamically.

What is the DOM?

When a web page is loaded, the browser creates a Document Object Model of the page. This model allows JavaScript to interact with all elements of the page.

Accessing HTML Elements

You can access HTML elements using different methods. The most common method is getElementById().

Example
Try this code

Changing HTML Content

JavaScript can change the content of HTML elements using the innerHTML property.

Example
Try this code

Changing CSS Styles

JavaScript can also change the style of HTML elements.

Example
Try this code

Changing Attributes

You can change HTML attributes such as images or links using JavaScript.

Example
Try this code

Adding Elements

JavaScript can create new HTML elements and add them to the page.

Example
Try this code

Removing Elements

JavaScript can also remove elements from the page.

Example
Try this code

Why the DOM is Important