This repository has been archived by the owner on Mar 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.js
106 lines (80 loc) · 2.75 KB
/
sample.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Homework for next class:
// Today's Kadae
// Make https://www.google.com/ website using only HTML and CSS
let num = 0;
let str = "string";
let arr = [];
let obj = {};
let fn = function () {};
// Inject `a` into `obj`
obj.a = "asdasdas";
const app = {
bookShelves: [["00", "01", "02", "03"], ["10", "11", "12", "13"], ["20", "21", "22", "23"], []],
loopArray: function () {
console.log("Length", this.bookShelves.length);
for (let i = 0; i < this.bookShelves.length; i++) {
const x = this.bookShelves[i];
// Change the value of:
// this.bookShelves[i][2] = "new";
console.log(x);
}
},
init: function () {
console.log("Start of the super APP");
// console.log("Bookshelf. Book at 1st floor and 2nd slot");
// console.log(this.bookShelves[1][2]);
// this.bookShelves[1][2] = "Lord of the rings";
// document.getElementById("12").innerHTML = this.bookShelves[1][2];
// console.log(this.bookShelves[1][2]);
// console.log("Bookshelf. Book at 2st floor and 3nd slot");
// console.log(this.bookShelves[2][3]);
// this.bookShelves[2][3] = "Great gatsby";
// document.getElementById("23").innerHTML = this.bookShelves[2][3];
// console.log(this.bookShelves[2][3]);
// this.bookShelves[3].push("Baseball bat");
// this.bookShelves[3].push("Baseball ball");
// this.bookShelves[3].push("Hat");
// this.bookShelves[3].push("Cup");
// console.log(this.bookShelves[3]);
// this.bookShelves[3].splice(1, 1);
// console.log(this.bookShelves[3]);
// console.log(this.bookShelves);
// this.loopArray();
this.playWithHtml();
},
playWithHtml: function () {
let el;
console.log("Lets play with HTML");
// Find element by ID
el = document.getElementById("containerId");
console.log("Found element:", el);
// Find element by class
el = document.getElementsByClassName("column");
console.log("Found element:", el);
// Create element
el = document.createElement("div");
console.log("Found element:", el);
// ---- Manipulate element ------ //
el = document.getElementById("containerId");
// Change the content
el.innerHTML = "<i>new content</i>";
// Change the style
el.style.backgroundColor = "red";
console.log("styling", el.style);
// change class
el.classList.remove("bold");
el.classList.add("bold");
console.log("classes", el.classList);
el = document.createElement("div");
el.id = "myNewElement";
el.style.fontSize = "50px";
el.classList.add("bold");
el.innerHTML = "im the new component";
document.body.appendChild(el);
console.log("new element", el);
// Find text
el = document.getElementById("text");
console.log("text", el);
},
};
app.init();