-
Notifications
You must be signed in to change notification settings - Fork 0
/
04_querySelector.js
34 lines (29 loc) · 1.03 KB
/
04_querySelector.js
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
/*
querySelector - for single
querySelectorAll - for multiple
*/
// querySelector
const memberShp = document.querySelector('#shp');
console.log(memberShp); //not node list output show element id shp
// so u can add background without index
memberShp.style.background = '#333';
memberShp.style.width = '16rem';
//querySelectorAll
const allMember = document.querySelectorAll('#shp');
// check use log if node-list use index
console.log(allMember); //here is node-list
const allMembers = [...allMember];
allMembers.forEach(function (items) {
items.style.color = '#fff';
items.style.textTransform = 'uppercase';
items.style.padding = '2rem';
});
// here u should use querySelector, so why?
// because only querySelector only acces for first
// change first-child be red background and actuallly
// u can write without first-child if want change lutfy be red
const beRed = document.querySelector('li');
beRed.style.background = 'coral';
// and last-child be blue
const beBlue = document.querySelector('li:last-child');
beBlue.style.background = 'blue';