-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvent_Listener.js
More file actions
79 lines (58 loc) · 2.42 KB
/
Event_Listener.js
File metadata and controls
79 lines (58 loc) · 2.42 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
73
74
75
76
77
78
79
// let parent = document.getElementsByClassName('container');
// function changeText(){
// let fpara = document.getElementById('fpara');
// fpara.textContent = "Good Morning! Priyanshu" ;
// }
// let fpara = document.getElementById('fpara');
// // Adding the event listener to the first paragraph.
// // This will change the text of the first paragraph when it is clicked.
// fpara.addEventListener('click',changeText);
// // removing the event listener from the first paragraph.
// // This will remove the event listener from the first paragraph.
// // fpara.removeEventListener('click',changeText);
// let anchorElement = document.getElementById('fanchor');
// anchorElement.addEventListener('click',function(event){
// event.preventDefault(); // This function stops the default behaviour of the element.
// anchorElement.textContent = "Clicked Done Bhaii.";
// anchorElement.style.textDecoration = 'none';
// });
// Method-1
// let fpara = document.getElementById('fpara');
// let spara = document.getElementById('spara');
// let tpara = document.getElementById('tpara');
// let fopara = document.getElementById('fopara');
// fpara.addEventListener('click',function(event){
// alert("You Have Clicked On Para : "+fpara.textContent);
// });
// spara.addEventListener('click',function(event){
// alert("You Have Clicked On Para : "+spara.textContent);
// });
// tpara.addEventListener('click',function(event){
// alert("You Have Clicked On Para : "+tpara.textContent);
// });
// fopara.addEventListener('click',function(event){
// alert("You Have Clicked On Para : "+fopara.textContent);
// });
// Method-2
// let paras = document.querySelectorAll('p');
// for(let i = 0 ; i < paras.length ; i++){
// let para = paras[i];
// para.addEventListener('click',function(event){
// alert("You Have Click on the Para : "+(i+1));
// alert(para.textContent);
// });
// }
// Method-3
// let paras = document.querySelectorAll('p');
// function alertFunction(event){
// alert("You Have Clicked On Para : "+event.target.textContent); // Event : click , Target : p , textContent : p.textContent
// }
// for(let i = 0 ; i < paras.length ; i++){
// let para = paras[i];
// para.addEventListener('click',alertFunction);
// }
// Method-4
// function alertFunction(event){
// alert("You Have Clicked On Para : "+event.target.textContent);
// }
// document.addEventListener('click',alertFunction);