Soft Technology web: JavaScript - HTML DOM methods

HTML DOM method is that you can (on the HTML element) executed action.

HTML DOM attribute is that you can set or change the HTML element values.

DOM programming interface

HTML DOM can be accessed (in other programming language can also be) using JavaScript.

In the DOM, all HTML elements are defined as objects.

Is a programming interface properties and methods for each object.

Property is that you can get or set value (such as changing content on HTML elements).

The method is able to complete your actions (such as adding or deleting HTML elements).

Examples

The following example changes the content id = "demo" the <p> element:

<html>
<body>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = "Hello World!";
</script>

</body>
</html>

 

In the above example, the getElementById method, while  innerHTML is a property.

getElementById method

Access HTML elements most commonly used method is to use the element of id.

In the above example, the getElementById method id = "demo" to locate the element.

innerHTML property

The easiest way to get element's content is  innerHTML property.

innerHTML property or alternatively may be used to obtain the content of HTML elements.

innerHTML property can be used to obtain or alter any HTML elements, including  <html> and  <body>.

Guess you like

Origin www.cnblogs.com/sysoft/p/12094749.html