-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.js
More file actions
57 lines (46 loc) · 1.41 KB
/
main.js
File metadata and controls
57 lines (46 loc) · 1.41 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
function changeColorMany(elements) {
for (const element of elements) {
element.style.backgroundColor = "yellow";
}
}
function changeColorOne(element) {
element.style.backgroundColor = "yellow";
}
/////////////////////////
//// DOM Traversal ////
/////////////////////////
// Universal (no direction)
// document.getElementById // document only method
// Downwards
// element.getElementsByClassName
// element.getElementsByTagName
// element.querySelector
// element.querySelectorAll
// element.children
// console.log(parent);
// Upwards
// element.parentElement
// element.closest
// Sideways
// element.nextElementSibling
// element.previousElementSibling
// combine using parentElement, children, and index
/////////////////////
//// Exercises ////
/////////////////////
/*
Practice traversing the DOM with the methods taught in this lesson. Uncomment the additional HTML in the index.html file and then do these tasks:
Select .characters with document.querySelector
Select .humans from .characters
Select all humans with querySelectorAll, starting from .humans
Select all hobbits with the "children" property of some element
Select Merry (the hobbit)
Select Sauron
Select .enemies from Sauron
Select Nazgûl
Select the .characters div from Nazgûl
Select Glorfindel
Select Elrond from Glorfindel
Select Legolas from Glorfindel
Select Arwen from Glorfindel
*/