forked from fterdal/DOM-1-StartingPoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
90 lines (63 loc) · 2.59 KB
/
Copy pathscript.js
File metadata and controls
90 lines (63 loc) · 2.59 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
console.log("Hello! If you see this, the script is working.");
/*
- [1] Select the section with an id of container without using querySelector.
- [2] Select the section with an id of container using querySelector.
- [3] Select all of the list items with a class of "second".
- [4] Select a list item with a class of third, but only the list item inside of the ol tag.
- [5] Give the section with an id of container the text "Hello!".
- [6] Add the class main to the div with a class of footer.
- [7] Remove the class main on the div with a class of footer.
- [8] Create a new li element.
- [9] Give the li the text "four".
- [10] Append the li to the ul element.
- [11] Loop over all of the lis inside the ol tag and give them a background color of "green".
- [12] Remove the div with a class of footer.
*/
//******ANSWERS******
//- [1] Select the section with an id of container without using querySelector.
console.log("1:");
const container = document.getElementById("container");
console.log(container);
//- [2] Select the section with an id of container using querySelector.
console.log("2:");
const container2 = document.querySelector("#container");
console.log(container2);
//- [3] Select all of the list items with a class of "second".
console.log("3:");
const secondClass = document.getElementsByClassName("second")
console.log(secondClass);
//- [4] Select a list item with a class of third, but only the list item inside of the ol tag.
console.log("4:");
const thirdClass = document.querySelector("ol .third")
console.log(thirdClass);
//- [5] Give the section with an id of container the text "Hello!".
console.log("5:");
//container.textContent = "Hello!";
//console.log(container);
//- [6] Add the class main to the div with a class of footer.
console.log("6:");
const footer = document.querySelector(".footer");
footer.classList.add("main");
//- [7] Remove the class main on the div with a class of footer.
console.log("7:");
footer.classList.remove("main");
//- [8] Create a new li element.
console.log("8:");
const element = document.createElement('li');
//- [9] Give the li the text "four".
console.log("9:");
element.textContent = "four";
//- [10] Append the li to the ul element.
console.log("10:");
const ulElement = document.querySelector("ul");
ulElement.append(element);
//- [11] Loop over all of the lis inside the ol tag and give them a background color of "green".
console.log("11:");
const ilElements = document.querySelectorAll("ol li");
for (let element of ilElements)
{
element.style.backgroundColor = "green";
}
//- [12] Remove the div with a class of footer.
console.log("12:");
footer.remove();