代码示例:(标识:htmldom_article_create)
<!DOCTYPE html>
<html>
<body>

<p>单击该按钮可创建包含 H1 和 P 元素的 ARTICLE 元素。</p>

<button onclick="myFunction()">试一试</button>

<script>
function myFunction() {
  var x = document.createElement("ARTICLE");
  x.setAttribute("id", "myArticle");
  document.body.appendChild(x);

  var heading = document.createElement("H1");
  var txt1 = document.createTextNode("Heading in Article");
  heading.appendChild(txt1);
  document.getElementById("myArticle").appendChild(heading);

  var para = document.createElement("P");
  var txt2 = document.createTextNode("Paragraph in article.");
  para.appendChild(txt2);
  document.getElementById("myArticle").appendChild(para);
}
</script>

</body>
</html>
运行结果: