-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDom.js
84 lines (63 loc) · 2.65 KB
/
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
78
79
80
81
// DOM (document object model)
// const ele = document.getElementById('heading') // this will return us the id or the node from the DOM tree
// console.log(ele)
// ele.innerHTML = "hello world" // this is for editing that node
// const ele = document.getElementsByClassName("list") // this is for class
// console.log(ele)
// const ele = document.querySelector("ul") // this will select the css part ( the first one and only one)
// console.log(ele)
// const ele = document.querySelectorAll("ul") // this will select all ul
// console.log(ele)
// const ele = document.querySelector("#heading")
// console.log(ele)
// ele.innerHTML = "Modified by javascript"
// // ele.style=`color:blue; // using tild we can write properties in new line
// // font-size:55px;
// // `
// ele.style = "color:dodgerblue; font-size:30px; font-family:Metropolis" // we can write also but not in new line, all should be in same line
// ele.classList.add("new-class")
// ele.classList.add("nsomething")
// ele.classList.remove("new-class") // we can only use these on single element or node
// console.log(ele.classList)
// const list = document.querySelector("ul")
// const todos = ["Eat food","Go for a run","Workout","Sleep"]
// todos.map(todo=>{
// const toAdd = document.createElement("li")
// text = document.createTextNode(todo)
// toAdd.appendChild(text)
// list.appendChild(toAdd)
// // both are same in one we are adding a text node then adding to the parent, incase of innerHTML it directly adds the html tag
// // toAdd.innerHTML = todo
// // toAdd.innerHTML = `<h1>${todo}</h1>`
// // console.log(toAdd)
// console.log(text)
// console.log(toAdd)
// list.appendChild(toAdd)
// })
// const timer = setInterval(() => { // this function will be invoked after every specified time
// console.log("Hi")
// }, 1000); // this is specified time
// setTimeout(() => {
// clearInterval(timer) // setInterval will be stopped
// }, 10000);
const timer = document.querySelector("#timer")
const secondHand = document.querySelector('div.second')
const minuteHand = document.querySelector('div.minute')
let time = 0;
const t = setInterval(() => {
time++;
minute = time / 60;
secondHand.style = `transform:rotate(${time * 6}deg)`
minuteHand.style = `transform:rotate(${minute * 6}deg)`
timer.innerHTML = time;
}, 1000)
const list = document.querySelector('ul')
fetch('https://jsonplaceholder.typicode.com/todos').then(response => {
response.json().then(todos => {
todos.map(todo => {
const toAdd = document.createElement("li")
toAdd.innerHTML = todo.title
list.appendChild(toAdd)
})
})
})