js
[javaScript] .remove() / .removeChild()
natrue
2021. 1. 12. 15:39
728x90
์๋ฐ์คํฌ๋ฆฝํธ๋ฅผ ์ด์ฉํ์ฌ
HTML ์์๋ฅผ ๋์ ์ผ๋ก ์ญ์ ํ๊ธฐ
1. remove : ์์๋ฅผ ์ญ์
// remove
function remove1Function(){
var veBtnRmv = document.getElementById("veBtnId");
veBtnRmv.remove();
}
2. removeChild : ๋ถ๋ชจ์๊ฒ์ ์์ ๊ฐ์ฒด๋ฅผ ๋ผ์ด๋ด๊ธฐ (=์ญ์ )
// removeChild
function remove2Function(){
var veList = document.getElementById("veList");
veList.removeChild(veList.childNodes[0]);
}
Test

| childNodes | ์์ ๋ ธ๋์ ์ ๊ทผ | NodeList ๋ฐํ |
| children | ์์ ์์์ ์ ๊ทผ | HTMLCollection ๋ฐํ |