JavaScript - HTML DOM metod

HTML DOM-metoder är de åtgärder du kan utföra (på HTML-element)Åtgärd.

HTML DOM-egenskaper är de HTML-element du kan ställa in eller ändraVärde.

DOM-programgränssnitt

HTML DOM kan nås genom JavaScript (kan också nås genom andra programmeringsspråk).

I DOM, alla HTML-element definierasobject.

The programming interface is the properties and methods of each object.

propertyis the value you can get or set (such as changing the content of an HTML element).

methodis the action 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>

Try it yourself

In the above example,getElementById ismethodwhile innerHTML isproperty.

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 property can be used to get or replace the content of an HTML element.

innerHTML properties can be used to get or change any HTML element, including <html> and <body>.