본문 바로가기

컴퓨터 프로그래밍/javascript

createElement, createTextNode

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>DOM</title>
<!--Document Object Modeling 
tree 구조로 메모리에 올라간 html문서를 조작할 때 사용한다. 
 -->
 <script type="text/javascript">
	window.onload = function() {
		//1. 노드 생성(태그, 내용) 
		var h1 = document.createElement('h1');
		var text = document.createTextNode('Hello Dom!!');
		
		//2. 노드 연결....기존 태그에 연결
		h1.appendChild(text);
		document.body.appendChild(h1);
	};
 </script>
</head>
<body>
</body>
</html>