-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOM.js
More file actions
72 lines (63 loc) · 1.74 KB
/
Copy pathDOM.js
File metadata and controls
72 lines (63 loc) · 1.74 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
//select by id
/*
let heading= document.getElementById("heading");
console.dir(heading); //cause it is an object
//select by classname
let headings = document.getElementsByClassName("heading-class");
console.dir(headings);
//queryselector
let elements = document.querySelector("p"); //1st element
let allElement =document.querySelectorAll("p");//all element
let div= document.querySelector("div");
console.dir(div);
div.innerText//inner shob text dekhabe
div.innerHTML//shb dekhabe html shho
div.textContent//hidden shoho shb text dekhay
//access h2 addd some text
let h2 = document.querySelector("h2");
console.dir(h2.innerText);
h2.innerText= h2.innerText + "after adding this text"
let divs= document.querySelectorAll(".box");
let idx=1;
for(i of divs)
{
i.innerText= `new value ${idx}`;
idx++
}
//style selector
let btn= document.createElement("button");
btn.innerText = "Click me";
btn.style.color= "white";
btn.style.backgroundColor = "red";
let div = document.querySelectorAll(".box");
div[0].append(btn);
//shobgula div e btn same chaile btn clone kore add korte hobe new var use kore
//event
btn.onclick=() =>{
div[0].style.backgroundColor="black";
};
let para = document.querySelector("p");
para.classList.add("newClass");
//event listener
//node.EventListener(event, callback)
btn.addEventListener("dblclick",() => {
div[0].style.backgroundColor="white";
})
*/
//toggle
let mode= document.querySelector("button");
let currMode="light";
let body= document.querySelector("body");
mode.addEventListener("click", () => {
if(currMode=="light")
{
currMode="dark";
body.classList.remove("light");
body.classList.add("dark");
}
else{
currMode="light";
body.classList.remove("dark");
body.classList.add("light");
}
});