Skip to content

Commit a23b877

Browse files
committed
querSelector() & querySelectorAll()
1 parent 1b1e8c2 commit a23b877

File tree

2 files changed

+35
-27
lines changed

2 files changed

+35
-27
lines changed

04_querySelector.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ querySelector - for single
33
querySelectorAll - for multiple
44
*/
55

6-
const listItem = document.querySelector('#listItem');
7-
// change background ul
8-
listItem.style.background = '#333';
9-
listItem.style.color = '#ddd';
6+
// querySelector
7+
const memberShp = document.querySelector('#shp');
8+
console.log(memberShp); //not node list output show element id shp
9+
// so u can add background without index
10+
memberShp.style.background = '#333';
11+
memberShp.style.width = '16rem';
1012

11-
// if only querySelector, show just first
12-
let shp = document.querySelector('.shp');
13-
console.log(shp); //lutfy
14-
// if use querySelectorAll
15-
shp = document.querySelectorAll('.shp');
16-
console.log(shp); //show node-list all
13+
//querySelectorAll
14+
const allMember = document.querySelectorAll('#shp');
15+
// check use log if node-list use index
16+
console.log(allMember); //here is node-list
1717

18-
// SHP
19-
const shpObject = [...shp];
20-
shpObject.forEach(function (items) {
18+
const allMembers = [...allMember];
19+
allMembers.forEach(function (items) {
20+
items.style.color = '#fff';
2121
items.style.textTransform = 'uppercase';
22-
items.style.fontSize = '1.25rem';
22+
items.style.padding = '2rem';
2323
});
2424

25-
// RHP
26-
const rhp = document.querySelectorAll('.rhp');
27-
const rhpObject = [...rhp];
28-
rhpObject.forEach(function (items) {
29-
items.style.textTransform = 'Capitalize';
30-
items.style.fontSize = '1.25rem';
31-
});
25+
// here u should use querySelector, so why?
26+
// because only querySelector only acces for first
27+
// change first-child be red background and actuallly
28+
// u can write without first-child if want change lutfy be red
29+
const beRed = document.querySelector('li');
30+
beRed.style.background = 'coral';
3231

33-
const memberRHP = document.querySelector('li:last-child');
34-
console.log(memberRHP);
32+
// and last-child be blue
33+
const beBlue = document.querySelector('li:last-child');
34+
beBlue.style.background = 'blue';

index.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,29 @@ <h2 id="title">Hello World</h2>
3030
</ul>
3131
</div> -->
3232

33-
<!-- getElementByClassName for className -->
33+
<!-- getElementByClassName for className
3434
<div class="container">
3535
<h2>hello there</h2>
3636
<ul class="list-item">
3737
<li>one piece</li>
3838
<li>naruto</li>
3939
<li>shinchan</li>
4040
</ul>
41-
</div>
41+
</div> -->
4242

43+
<!-- querySelector & querySelectorAll -->
44+
<h2>SHP Pirates</h2>
45+
<ul id="shp">
46+
<li id="members">lutfy</li>
47+
<li id="members">zoro</li>
48+
<li id="members">sanji</li>
49+
<li id="members">ussop</li>
50+
</ul>
4351
<!-- source js -->
4452
<!-- <script src="/01_getElementById.js"></script> -->
4553
<!-- <script src="/02_getElementByTagName.js"></script> -->
46-
<script src="/03_getElementByClassName.js"></script>
47-
<!-- <script src="https://github.com/04_querySelector.js"></script> -->
54+
<!-- <script src="https://github.com/03_getElementByClassName.js"></script> -->
55+
<script src="/04_querySelector.js"></script>
4856
<!-- <script src="/05_children.js"></script> -->
4957
<!-- <script src="/06_parentElement.js"></script> -->
5058
<!-- <script src="/07_nextSibling_previous.js"></script> -->

0 commit comments

Comments
 (0)