:::: 개발 ::::/::: JSCRIPT :::

Dom(Document Object Model ) 이해하기 예제 1

nayha 2012. 5. 12. 15:32

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>Insert title here</title>

<script type="text/javascript">

// 화면 버튼 누를때 마다 버튼 증가

// 증가된 버튼 클릭시 클릭 버튼 제거

window.onload = function() {

var btn = document.getElementById("btn");


btn.addEventListener('click', function(){

var newBtn = document.createElement('button');

newBtn.innerHTML = "newb";

document.body.appendChild(newBtn);

newBtn.addEventListener('click',function(){

document.body.removeChild(newBtn);

});

});

}


</script>

</head>

<body>

<button id = "btn">create</button>

</body>

</html>

반응형