-
Notifications
You must be signed in to change notification settings - Fork 129
/
The DOM.js
executable file
·77 lines (57 loc) · 1.98 KB
/
The DOM.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
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
/*
* The DOM
* Document Object Model
*
*/
/*
- Programming interface for HTML & XML documents.
- Provides a structured representation of the document
- Defines methods to access the structure and manipulate it
- Connects web pages to scripts or programming languages
- DOM is NOT a programming language, it provides a model of a web page
- The page content is stored in the DOM and can be accessed and manipulated in JavaScript
- "The DOM provides a representation of the document as a structured group of nodes and objects that have properties and methods." -Mozilla Developer Network
*/
//noprotect
const dummyDiv = document.querySelector(".dummy span");
const testDiv = document.getElementById("test");
const element = document.getElementById("footer");
const elID = element.id;
const replacementID = "bottom";
element.id = replacementID;
console.log(element);
const el = document.getElementsByTagName("div");
const footerDiv = el[el.length - 1];
footerDiv.id = "footer";
const purpleDivs = document.querySelectorAll(".purple");
for(const prop of purpleDivs) {
prop.classList.add("foo");
}
setInterval(() => {
for(const prop of purpleDivs) {
prop.classList.toggle("foo");
}
}, 3000);
newElement.innerText = "I was created by SCIENCE!";
newElement.classList.add("purple", "foo");
creationDiv.appendChild(newElement);
const myFaveIceCreams = ["vanilla", "rocky road", "strawberry", "chocolate"];
const creationDiv = document.getElementById("created");
const newElement = document.createElement("div");
const newUL = document.createElement("UL");
for(let i = 0 ; i < myFaveIceCreams.length ; i++) {
const newLI = document.createElement("LI");
newLI.innerText = myFaveIceCreams[i];
newUL.appendChild(newLI);
}
newElement.appendChild(newUL);
creationDiv.appendChild(newElement);
function removeIceCream(t) {
for(const prop of newUL.childNodes) {
if(prop.innerText === t) {
newUL.removeChild(prop);
}
}
}
removeIceCream("vanilla");
removeIceCream("rocky road");