the murmurous sea

JS DOM: how to insert a new node AFTER an existing node 본문

#dev/개념정리

JS DOM: how to insert a new node AFTER an existing node

lunacer 2020. 5. 1. 13:15

[Background]

JavaScript DOM provides the insertBefore() method that allows you to insert a new node after an existing node as a child node. However, it has not supported the insertAfter() method yet.

 

[To insert a new node after an existing node as a child node]

: use the insertBefore() method and the nextSibling property. 
: to insert a new node before an existing node as a child of a parent node.

1. createElement() method: Create a new HTML element.

2. nextSibling property: Select the next sibling node of the existing node.
3. parentNode property: Select the parent node of the existing node
4. insertBefore() method: on the parent node to insert a new element before that immediate sibling node.

example code is in here:
https://www.javascripttutorial.net/javascript-dom/javascript-insertafter/

'#dev > 개념정리' 카테고리의 다른 글

HTML DOM: insertBefore()  (0) 2020.05.02
선언적 함수 vs 함수표현식 vs 익명함수 (waiting list)  (0) 2020.05.02
HTML, JS: DOM  (0) 2020.05.01
callback  (0) 2020.05.01
JS ES5: reduce()  (0) 2020.04.30
Comments