forked from OakAcademy/JavaScript-Beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
139 lines (107 loc) · 3.66 KB
/
Copy pathscript.js
File metadata and controls
139 lines (107 loc) · 3.66 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
var h1Element = document.querySelector('h1');
h1Element.style.color = 'blue';
var isYellow = false;
var bodyElement = document.querySelector('body')
setInterval(function () {
if (isYellow) {
bodyElement.style.background = 'white';
} else {
bodyElement.style.background = 'yellow';
}
isYellow = !isYellow;
}, 1000);
*/
/*
var selectWithId = document.getElementById('oakParagraph');
console.log(selectWithId);
var selectWithClass = document.getElementsByClassName('background');
console.log(selectWithClass);
var selectWithTag = document.getElementsByTagName('h1');
console.log(selectWithTag);
var selectWithqueryId = document.querySelector('#oakParagraph');
console.log(selectWithqueryId);
var selectWithqueryClass = document.querySelector('.background');
console.log(selectWithqueryClass);
var selectWithqueryAllClass = document.querySelectorAll('.background');
console.log(selectWithqueryAllClass);
*/
////////////////////// MANIPULATION METHODS //////////////////////
/*
var divToManipulate = document.querySelector('.background');
divToManipulate.style.height = '50px';
divToManipulate.style.width = '400px';
divToManipulate.style.backgroundColor = 'red';
divToManipulate.style.fontSize = '30px';
divToManipulate.style.border = '5px solid black';
divToManipulate.classList.add('addClass');
divToManipulate.classList.remove('addClass');
divToManipulate.classList.toggle('addClass');
*/
/*
var paragraph = document.querySelector('#oakParagraph');
//paragraph.textContent = 'OAK academy is the best, really';
paragraph.innerHTML = 'Oak academy is <strong>great</strong>'
*/
////////////////////// MANIPULATE ATTRIBUTES //////////////////////
/*
var myLink = document.querySelector('a');
console.log(myLink.getAttribute('href'));
myLink.setAttribute('href', 'https://www.facebook.com/')
console.log(myLink.getAttribute('href'));
myLink.textContent = 'go to facebook'
*/
////////////////////// EVENT HANDLERS //////////////////////
/*
var button = document.querySelector('#btn1');
var title = document.querySelector('#OAKTitle');
button.addEventListener('click', function () {
console.log('You clicked the button');
title.style.backgroundColor = 'red'
});
var listParent = document.querySelector('ul');
listParent.addEventListener('click', function (event) {
console.log('You clicked the ul');
event.target.style.backgroundColor = 'blue';
})
////////////////////// QUIZ SOLUTION //////////////////////
var listItems = document.querySelectorAll('li');
console.log('listItems', listItems);
for (var i = 0; i < listItems.length; i++) {
listItems[i].addEventListener('click', function () {
this.style.color = 'white';
})
}
*/
/*
var oakParagraph = document.querySelector('#oakParagraph');
function toggleBackground() {
oakParagraph.classList.toggle('toggleBackground');
}
oakParagraph.addEventListener('click', toggleBackground);
*/
/*
var firstTodoItem = document.querySelector('.todoItem');
firstTodoItem.addEventListener('mouseover', function () {
firstTodoItem.style.backgroundColor = 'blue';
firstTodoItem.style.color = 'white';
})
firstTodoItem.addEventListener('mouseout', function () {
firstTodoItem.style.backgroundColor = 'white';
firstTodoItem.style.color = 'black';
})
*/
var todoListItems = document.querySelectorAll('.todoItem');
for (var i = 0; i < todoListItems.length; i++) {
todoListItems[i].addEventListener('mouseover', function () {
this.style.backgroundColor = 'blue'
this.style.color = 'white'
})
todoListItems[i].addEventListener('mouseout', function () {
this.style.backgroundColor = 'white'
this.style.color = 'black'
})
todoListItems[i].addEventListener('click', function () {
this.classList.add('okay');
})
}