JavaScript - HTML DOM Methods


HTML DOM methods are like actions you can take on HTML Elements.

HTML DOM properties are values associated with HTML elements that you can modify or update.


The DOM Programming Interface

You can use JavaScript (or other programming languages) to interact with the HTML DOM.

In the DOM, every HTML element is considered as an objects.

The programming interface consists of the characteristics and actions of each object.

A property is a value that you can either retrieve or modify, such as altering the content of an HTML element.

A method is something you can do, like adding or deleting an HTML element.


Example

The code snippet below updates the content inside a paragraph (p) element identified by the id="demo". It modifies the content using the innerHTML property:

In the given instance, getElementById is a action, and innerHTML is a attribute.


The getElementById Method

The usual method to reach an HTML element is by using the element's id.

In the example provided, the getElementById method is utilized with id="demo" to locate the specified element.


The innerHTML Property

The simplest method to retrieve the content of an element is by utilizing the innerHTML property.

The innerHTML property is handy for retrieving or changing the content of HTML elements.

The innerHTML property allows you to retrieve or modify any HTML element, such as <body> and <html>.