Top / Programming / JavaScript / Dom / appendChild()

appendChild(newNode)

子ノードの最後に、ノード(newNode)を追加する。

function add() {
  var newNode = document.createElement("LI");
  var text = document.createTextNode("追加しました。");
  newNode.appendChild(text);

  var parent = document.getElementById("sample");
  parent.appendChild(newNode);
}