-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventextra.js
87 lines (38 loc) · 1.35 KB
/
eventextra.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
let btn = document.getElementById("btn")
let btn1 = document.getElementById("btn1")
btn.addEventListener("click",()=>{
console.log("hello i m clicked");
alert("BOOM I M HERE")
document.querySelector(".box").innerHTML="i m changed now !"
})
btn1.addEventListener("dblclick",()=>{
let input1=prompt("yooo !")
console.log(input1);
})
//event bubbling
let child1=document.querySelector(".child")
let child2=document.querySelector(".childcontainer")
let child3=document.querySelector(".container1")
child1.addEventListener("click",(e)=>{
e.stopPropagation()
alert("child was cliked")
})
child2.addEventListener("click",(e)=>{
e.stopPropagation()
alert("child-container was cliked")
})
child3.addEventListener("click",(e)=>{
e.stopPropagation()
alert("container-1 was cliked")
console.log(e);
})
// setInterval(()=>{
// const numbersofcolors = ["red", "green","yellow","black","blue"];
// const randomColorinthebody = numbersofcolors[Math.floor(Math.random() * numbersofcolors.length)];
// child3.style.background = randomColorinthebody;
// },3000)
setTimeout(() => {
const numbersofcolors = ["red", "green","yellow","black","blue"];
const randomColorinthebody = numbersofcolors[Math.floor(Math.random() * numbersofcolors.length)];
child2.style.background = randomColorinthebody;
},3000)