document.createTextNode() 예제 - 텍스트노드만 생성
<button onclick="homzzang()">클릭</button> <script> function homzzang() { var t = document.createTextNode("홈짱닷컴 Homzzang.com"); document.body.appendChild(t); } </script> 결과보기
<button onclick="homzzang()">클릭</button>
<script>
function homzzang() {
var t = document.createTextNode("홈짱닷컴 Homzzang.com");
document.body.appendChild(t);
}
</script>
결과보기
결과값: 홈짱닷컴 Homzzang.com
document.createTextNode() 예제 - (요소노드 + 텍스트노드) 생성
<button onclick="homzzang()">클릭</button> <script> function homzzang() { var h = document.createElement("H1"); var t = document.createTextNode("홈짱닷컴 Homzzang.com"); h.appendChild(t); document.body.appendChild(h); } </script> 결과보기
var h = document.createElement("H1");
h.appendChild(t);
document.body.appendChild(h);