Dom Getting Started Tutorial: Properties and methods of DOM
Properties and methods define the DOM of the HTML of the programming interface.
Programming interface
The HTML of the DOM model as a set of node objects. Nodes can take advantage of JavaScript or other programming languages. In this tutorial, we use JavaScript.
The definition of the DOM of a programming interface is a set of standard properties and methods.
Performance is often referred to as something (ie, nodename "P").
Methods are often called things to do this (ie delete "P").
The DOM properties of the HTML
Here are some typical DOM properties:
X.innerhtml-the intrinsic value of the literal x (an H tml Element)
X.nodename-Name of X
Value of X.nodevalue-x
X.parentnode-The parent node's X
X.childnodes-X of child nodes
X.attributes-the properties of the node X
Note: The above list, X is a node object (HTML Element).
The HTML DOM method
X.getelementbyid (logo)-the element obtained with the specified I D
X.getelementsbytagname (name)-Let all elements with the specified tag name
X.appendchild (node)-Inserts a child node as X
X.removechild (node)-Deletes a child node from X
Note: The above list, X is a node object (HTML Element).
InnerHTML
The easiest way to get or modify an element of content is to use the innerHTML property.
innerHTML is not an integral part of the Consortium DOM specification. However, it supports all major browsers.
The innerHTML property is useful for returning or replacing HTML elements of content (including
For example
JavaScript code allows text to be "introduced" from the ID of the <p> element in an HTML file:
Text = document.getElementById ("Introduction"). InnerHTML
In implementing the statement, the text will hold the value of "the World Hello!" ”
Explain:
FILE-Current H tml file
getElementById ("Introduction")-< p> elements of I D to "Introduction"
InnerHTML-Inner h tml elements
In the above example, getElementById is a method, and INNERHMTL is a property.
You try it.
Zi and NodeValue
The format of the consortium Dom is given in such a way as to obtain the content of a piece of content such as:
JavaScript code allows text to be "introduced" from the ID of the <p> element in an HTML file:
Text = document.getElementById ("Introduction"). Child [0]. NodeValue
In implementing the statement, the text will hold the value of "the World Hello!" ”
Explain:
FILE-Current H tml file
getElementById ("Introduction")-< p> elements of I D to "Introduction"
Sub [0]-the first child's < p> element (text node)
NodeValue-Value node (text itself)
In the example above, getElementById is a method, and the performance of the child and NodeValue.
You try it.
In this tutorial, we will primarily use the innerHTML property. However, learning the above method is useful for understanding the tree-like structure of the DOM and processing XML files.