Source
<script>
var node = document.getElementById("myList2").lastChild;
list2의 lastChild인 Cake를 꺼내서
var list1 = document.getElementById("myList1");
list1.insertBefore(node, list.childNodes[1]);
list1의 두번째 childNode인 Tea앞에 삽입
var newItem = document.createElement("LI");
새로운 li를 만들어서
var textnode = document.createTextNode("Apple");
Apple이라는 textNode를 만들어서
newItem.appendChild(textnode);
새로 만든 li에다가 넣고
var list2 = document.getElementById("myList2");
list2.appendChild(newItem);
list2에다가 추가 시킨다.
</script>
Result
원래의 List
| List 1 | List 2 |
|---|---|
|
|
javascript실행후 List
| List 1 | List 2 |
|---|---|
|
|
댓글 없음:
댓글 쓰기