-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex3.32.domjQuery.html
More file actions
83 lines (77 loc) · 2.58 KB
/
Copy pathex3.32.domjQuery.html
File metadata and controls
83 lines (77 loc) · 2.58 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>domjQuery 실습 3</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(function () {
// 버튼을 클릭 했을때 e target content에 따라 조건을 작성
$('button').click((e) => {
// div, 너비, 높이 변수에 할당
const divBox = $('div');
const divWidth = divBox.width();
const divHeight = divBox.height();
switch (e.target.textContent) {
// 배경색 blue 로 바꾸기
case '배경색blue':
divBox.css('background-color', 'blue');
break;
// 배경색 red 로 바꾸기
case '배경색red':
divBox.css('background-color', 'red');
break;
// div 크기, 높이를 가져와서 2배 늘리기
case '크기X2':
divBox.css('width', `${divWidth * 2}px`);
divBox.css('height', `${divHeight * 2}px`);
break;
// div 크기, 높이를 가져와서 2배 줄이기
case '크기/2':
divBox.css('width', `${divWidth / 2}px`);
divBox.css('height', `${divHeight / 2}px`);
break;
// div 에 기존 red 클래스가 있으면 삭제하고, 배경색도 초기화 후, blue 클래스 추가
case 'blue클래스':
divBox.removeClass('red');
divBox.css('background-color', '');
divBox.addClass('blue');
break;
// div 에 기존 blue 클래스가 있으면 삭제하고, 배경색도 초기화 후, red 클래스 추가
case 'red클래스':
divBox.removeClass('blue');
divBox.css('background-color', '');
divBox.addClass('red');
break;
}
});
}); //$(function({})) 라인
</script>
<style>
div {
width: 100px;
height: 100px;
background-color: yellow;
border: 1px solid #000;
}
.blue {
background-color: blue;
}
.red {
background-color: red;
}
</style>
</head>
<body>
<div></div>
<p>
<button>배경색blue</button>
<button>배경색red</button>
<button>크기X2</button>
<button>크기/2</button>
<button>blue클래스</button>
<button>red클래스</button>
</p>
</body>
</html>