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

chapter10 : DOM_style 본문

WEB.JS/08.DOM_JS

chapter10 : DOM_style

GAWON 2023. 5. 22. 09:29
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
onload = changeStyle;  //괄호 없이!! 함수를 바로 넣어서 실행시키겠다

```
function changeStyle(){
	//1. css 속성을 그대로 사용하는 경우( 하이픈 없이 단어 하나로 구성된 속성들)
	//   .(마침표)표기법 사용
	var h1 = document.querySelector("#heading");
	h1.style.color = "red";
	h1.style.width = "400px";
	h1.style.height = "100px";
	h1.style.background = "pink";
	h1.style.border = "1px solid black";

	// 2. css 속성을 변경해서 사용하는 경우 ( 하이픈으로 이어진 두 단어 이상으로 구성된 속성들)
	//   하이픈(-)을 제거하고, camel case 형식으로 변경
	//  .(마침표) 표기법 사용
	var box = document.querySelector("#box");
	box.style.fontFamily = "궁서";
	//글씨 크기 20px, 글씨 굵기 : 두껍게
	box.style.fontSize = "20px";
	box.style.fontWeight = "bold";

	//3. css 속성을 그대로 사용해야 한다면!
	//   [](대괄호) 표기법 사용
	var pLise = document.querySelectorAll("p");
	pLise[2].style["color"] = "red";
	pLise[2].style["background-color"] = "yellow";
}

```

</script>
</head>
<body>
<h1 id="heading">DOM</h1>
<div id="box">
<P>Document</P>
<p>Object</p>
<p>Model</p>
</div>

</body>
</html>

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

chapter07 : DOM_getElementsByTagName  (0) 2023.05.22
chapter08 : DOM_getElementsByClassName  (0) 2023.05.22
chapter09 : DOM_querySelector  (0) 2023.05.22
chapter11 : DOM_문제  (0) 2023.05.22
chapter12 : DOM_문제  (0) 2023.05.22