The HTML DOM enables you to navigate within a node tree using node relationships.

HTML DOM navigation syntax

getElementsByTagName() method returns the node list. A node list is an array of nodes.

HTML DOM navigation example

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<p>Hello World!</p>
<p>DOM 是非常有用的!</p>
<p>这个实例演示了 <b>length</b> 属性。</p>

<script>
x=document.getElementsByTagName("p");
for (i=0;i<x.length;i++)
{ 
    document.write(x[i].innerHTML);
    document.write("<br>");
}
</script>
</body>
</html>

Run instance »

Click the "Run instance" button to view the online instance