Notice
Recent Posts
Recent Comments
Link
«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter04 : DOM생성 본문

WEB.JS/08.DOM_JS

chapter04 : DOM생성

GAWON 2023. 5. 23. 09:15
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
onload = function() {
//1. 이미 있는 요소에 속성 추가(변경)
document.getElementById("img1").setAttribute("src","../images/bart.jpg");

```
	//2. 새 요소를 만들어서 추가(img)
	var imgElement = document.createElement("img");
	imgElement.src = "../images/bart.jpg";
	imgElement.alt = "구글 사진";
	imgElement.width = 200;
	document.body.appendChild(imgElement);

}

```

</script>
</head>
<body>
<img id="img1">

<br>
</body>
</html>

'WEB.JS > 08.DOM_JS' 카테고리의 다른 글

chapter02 : DOM생성  (0) 2023.05.23
chapter03 : DOM생성  (0) 2023.05.23
chapter05 : DOM삭제  (0) 2023.05.23
chapter06 : DOM_getElementById  (0) 2023.05.23
chapter07 : DOM_getElementsByTagName  (0) 2023.05.22