-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodeClass.js
More file actions
44 lines (29 loc) ยท 1.6 KB
/
nodeClass.js
File metadata and controls
44 lines (29 loc) ยท 1.6 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
/* --- // $ [javascript.info] ํ์ ๋
ธ๋ ๊ฐ์ ์ธ๊ธฐ
ul๊ณผ li ๋
ธ๋๋ก ๊ตฌ์ฑ๋ ํธ๋ฆฌ ๊ตฌ์กฐ ๋ฌธ์๊ฐ ์๋ค๊ณ ๊ฐ์ ํด ๋ด
์๋ค.
li ๋
ธ๋ ์ ์ฒด๋ฅผ ๋์์ผ๋ก ์๋์ ๊ฐ์ ์์
์ ํ๋ ค ํฉ๋๋ค. ์กฐ๊ฑด์ ๋ง์กฑ์ํฌ ์ ์๋ ์ฝ๋๋ฅผ ์์ฑํด ๋ณด์ธ์.
1. li ๋
ธ๋ ์์ ์๋ ํ
์คํธ๋ฅผ ์ถ๋ ฅ
2. li ๋
ธ๋ ์๋์ ์๋ ๋ชจ๋ <li> ํ๊ทธ์ ๊ฐ์๋ฅผ ์ถ๋ ฅ
https://ko.js.cx/task/tree-info/solution/
------------------------------------------------------- */
// 1. li ๋
ธ๋ ์์ ์๋ ํ
์คํธ๋ฅผ ์ถ๋ ฅ
for (let li of document.querySelectorAll('li')){
let title = li.firstChild.data;
// let title = li.firstElementChild
title = title.trim();
let count = li.querySelectorAll('li').length;
console.log(`${title} : ${count}`)
}
/* --- // $ [javascript.info] ์ฃผ์ ์์ ํ๊ทธ
์คํฌ๋ฆฝํธ๋ฅผ ์คํ ๊ฒฐ๊ณผ๋ฅผ ์์ธกํด๋ณด์ธ์.
------------------------------------------------------- */
let body = document.body; // <body><!--BODY--></body>
body.innerHTML = "<!--" + body.tagName + "-->";
// alert( body.firstChild.data ); // ์ผ๋ฟ ์ฐฝ์ ์ด๋ค ๋ด์ฉ์ด ์ถ๋ ฅ๋ ๊น์?
// let answer = prompt('๋ต์ ๋ฌด์์ธ๊ฐ์?','')
(body.firstChild.data == "BODY") && ('์ ๋ต์
๋๋ค!')
/*
<body>์ ์ฝํ
์ธ ๊ฐ <!--BODY-->๋ก ๋์ฒด๋๋ค.
tagName์ ํญ์ ๋๋ฌธ์์ด๊ธฐ ๋๋ฌธ์ body.tagName์ "BODY"๊ฐ ๋๋ค.
<body>์ ์ฝํ
์ธ ๊ฐ ๊ต์ฒด๋๋ฉด์ ์ฃผ์์ด ์ ์ผํ ์์ ๋
ธ๋๊ฐ ๋๋ค.
์ฃผ์ ๋
ธ๋์ data ํ๋กํผํฐ์ ์ฃผ์ ๋ด์ฉ(<!--...--> ์์ชฝ์ ๋ด์ฉ)์ด ์ ์ฅ๋๋ฏ๋ก data ํ๋กํผํฐ์ ๊ฐ์ "BODY"์
๋๋ค.
*/