appendChild()

jayden·2020년 4월 24일
0

javascript

목록 보기
1/5

The appendChild() method appends a node as the last child of a node.

appendChild() 메소드는 마지막 자녀의 노드에 노드로서 추가한다.

Tip: If you want to create a new paragraph, with text, remember to create the text as a Text node which you append to the paragraph, then append the paragraph to the document.

새로운 단락이나 텍스트를 추가하기를 원한다면 네가 만든 단락에 추가할 텍스트를 생성하고 다음에 문서의 단락에 추가해라.

Tip: Use the insertBefore() method to insert a new child node before a specified, existing, child node.

Append an item in a list:

var node = document.createElement("LI");                 // Create a <li> node
var textnode = document.createTextNode("Water");         // Create a text node
node.appendChild(textnode);                              // Append the text to <li>
document.getElementById("myList").appendChild(node);     // Append <li> to <ul> with id="myList"

Before appending:

Coffee
Tea

After appending:

Coffee
Tea
Water

profile
DevOps 너로 정했다!

0개의 댓글