Latest web development tutorials

HTML DOM property

Property is the value of node (HTML elements), you can get or set.


Programming Interface

By JavaScript (and other programming languages) to HTML DOM access.

All HTML elements are defined as an object, and the programming interface is object method and object properties.

The method is an operation (such as adding or modify elements) that you can perform.

Property is that you can get or set value (for example, node name or content).


innerHTML property

The easiest way to get the content of the element is to use the innerHTML property.

innerHTML property to get or replace the content of HTML elements useful.

Examples

The following code gets the id = "intro" the <p> element innerHTML:

Examples

<html>
<body>

<p id="intro">Hello World!</p>

<script>
var txt=document.getElementById("intro").innerHTML;
document.write(txt);
</script>

</body>
</html>

try it"

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

lamp

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



NodeName attribute specifies the name of the node.

  • nodeName is a read-only
  • nodeName with the same tag name of an element node
  • nodeName attribute nodes with the same attribute name
  • nodeName text node is always #text
  • nodeName document node is always #document

Note: nodeName always contain uppercase HTML element tag name.


nodeValue property

NodeValue property value specified node.

  • nodeValue element node is undefined or null
  • nodeValue text node is the text itself
  • nodeValue attribute node is an attribute value

Gets the value of the element

The following example will retrieve <p id = "intro"> tag text node values:

Examples

<html>
<body>

<p id="intro">Hello World!</p>

<script type="text/javascript">
x=document.getElementById("intro");
document.write(x.firstChild.nodeValue);
</script>

</body>
</html>

try it"


nodeType property

nodeType property returns the type of node. nodeType is read-only.

Node types are more important:

Element Type NodeType
element 1
Attributes 2
text 3
Note 8
File 9