-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
106 lines (56 loc) · 1.83 KB
/
app.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
//DOM MANIPULATIONS
// dom methods ->
const title=document.getElementById('main-heading');
console.log(title);
const listItem=document.getElementsByClassName('list-items');
console.log(listItem);
const listItems=document.getElementsByTagName('li');
console.log(listItems);
const container=document.querySelector('div');
console.log(container);
const containers=document.querySelectorAll('div');
console.log(containers);
// dom css properties->
const title=document.querySelector('#main-heading');
title.style.color='green';
const listItems=document.querySelectorAll('list-items');
listItems.style.fontSize='10rem';
//creating elements
const ul=document.querySelector('ul');
const li=document.createElement('li');
//appending elements
ul.append(li);
//modifying the text
li.innerText='arrogant';
//modifying attributes and classes
li.classList.remove('list-items');
//Remove elements
li.remove();
//Traversing the Dom
//parent Node traversAL
let ul=document.querySelector('ul')
console.log(ul.parentNode);
console.log(ul.parentElement);
console.log(ul.parentNode.parentNode);
console.log(ul.childNodes);
console.log(ul.firstChild);
console.log(ul.lastChild);
ul.childNodes[1].style.backgroundColor='blue'
console.log(ul.previousSibling);
console.log(ul.nextSibling);
const div=document.querySelector('div');
console.log(div.childNodes);
console.log(ul.previousElementSibling);
console.log(ul.nextElementSibling);
//Event Listners
//element.addEventListeners("click",function);
const buttonTwo=document.querySelector('.btn-2');
function alertBtn(){
alert('I love Reactjs')
}
buttonTwo.addEventListener("click",alertBtn);
const newBackgroundColor=document.querySelector('.box-3');
function changeBgColor(){
newBackgroundColor.style.backgroundColor="Green"
}
newBackgroundColor.addEventListener("mouseover",changeBgColor);