Notice
Recent Posts
Recent Comments
Link
«   2026/06   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
Archives
Today
Total
관리 메뉴

학습기록남기기

2022_05_26_JS_4일 본문

수업_정리

2022_05_26_JS_4일

backend_na 2022. 5. 26. 21:38

const $id=document.getElementById('id');

$id.childNodes; //NodeList 
$id.children; // HTMLCollection
$id.firstChild;
$id.firstElementChild;
$id.lastElementChild;
$id.hasChildNodes();

------------------------------------------
$id.parentNode;
$id.previousElementSibling;
$id.nextElementSibling;

---------------------------------------------

$id.innerHtml+='<li class='ba'>baba</li>';

-------------------------------------------

const $fruits=document.getElementById('fruits');
//1.요소 노드 생성(추가는 따로입니다.)
const $newLi=document.createElement('li');
//2.텍스트 삽입
$newLi.textContent='Banana';
//3.ul에 새로운 li 노드 추가
$fruits.appendChild($newLi);

$fruits.insertBefore($newLi,$fruits.firstElementChild);

const $frag=document.createDocumentFragment();
        
        for(let f of fruitName){
            const $li=document.createElement('li');
            $li.textContent=f;
            $frag.appendChild($li);
        }

        $fruits.appendChild($frag);
-------------------------------------------------------------------


//apple의 사본 생성(얕은 복사 : 자기 자신 노드만 복사 )
    const $shallowClone=$apple.cloneNode();
    console.log($shallowClone);

    $shallowClone.textContent=$apple.textContent;
    $fruits.appendChild($shallowClone);


    //apple의 사본 생성(깊은 복사 : 자기 자신을 포함한 모든 자손 노드를 복제 )
    const $deeppClone=$apple.cloneNode(true);
    $fruits.appendChild($deeppClone);



-----------------------------------------------
$fruits.replaceChild($mango,$fruits.firstElementChild);

$fruits.removeChild($fruits.lastElementChild);

'수업_정리' 카테고리의 다른 글

2022_05_30_JS_6일  (0) 2022.05.31
2022_05_27_JS_5일  (0) 2022.05.27
2022_05_25_JS_3일  (0) 2022.05.25
2022_05_24_JS_2일  (0) 2022.05.24
2022_05_23_ JS_1일  (0) 2022.05.23