JavaScript - HTML DOM Method
- Previous Page DOM Introduction
- Next Page DOM Documentation
HTML DOM methods are the actions that you can perform on HTML elementsAction.
HTML DOM properties are the HTML elements that you can set or changeValue.
DOM programming interface
The HTML DOM can be accessed through JavaScript (and also through other programming languages).
In the DOM, all HTML elements are defined asObject.
Programming interface is the properties and methods of each object.
Propertiesare values you can get or set (such as changing the content of HTML elements).
methodsare actions you can perform (such as adding or deleting HTML elements).
Example
The following example changes the content of the <p> element with id="demo":
<html> <body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = "Hello World!"; </script> </body> </html>
In the above example,getElementById
aremethodswhile innerHTML
areProperties.
getElementById method
The most common way to access an HTML element is to use the element's id.
In the above example,getElementById
Method uses id="demo" to find the element.
innerHTML property
The simplest way to get the content of an element is to use innerHTML
.
innerHTML
Properties can be used to get or replace the content of HTML elements.
innerHTML
Properties can be used to get or change any HTML element, including <html>
and <body>
.
- Previous Page DOM Introduction
- Next Page DOM Documentation