[Java Script] Nodes methods

createElement

const para = document.createElement("p");

createTextNode

const node = document.createTextNode("seokwon");

appendChild

para.appendChilde(node);

remove

document.getElementById("p1").remove();

removeChild

const parent = document.getElementById("div1");
const child = parent.childNodes[1];
parent.removeChild(child);

replaceChild

const parent = document.getElementById("div1");
const child = parent.childNodes[1];

const newp = document.createElement("p");
const newtext = document.createTextNode("seokwon");
newp.appendChild(newtext);

parent.replaceChild(newp, child);

좋은 웹페이지 즐겨찾기