- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_querySelector.js
More file actions
Latest commit
34 lines (29 loc) · 1.03 KB
/
Copy path04_querySelector.js
File metadata and controls
34 lines (29 loc) · 1.03 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
/*
querySelector - for single
querySelectorAll - for multiple
*/
// querySelector
constmemberShp=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
constallMember=document.querySelectorAll('#shp');
// check use log if node-list use index
console.log(allMember);//here is node-list
constallMembers=[...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
constbeRed=document.querySelector('li');
beRed.style.background='coral';
// and last-child be blue
constbeBlue=document.querySelector('li:last-child');
beBlue.style.background='blue';