generated from pushdev-code/programming-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.js
More file actions
26 lines (20 loc) · 859 Bytes
/
main.js
File metadata and controls
26 lines (20 loc) · 859 Bytes
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
function log(msg) {
logElement.innerHTML += '<p class="result" >' + msg + '</p>';
}
function clearOutput() {
logElement.innerHTML = '';
}
function capture() {
log('capture: ' + this.firstChild.nodeValue); // get value of first child element
}
function bubble() {
log('bubble: ' + this.firstChild.nodeValue); // get value of first child element
}
let logElement = document.querySelector('.log'); // get log section
let divs = document.getElementsByTagName('div'); // get and save all the divs into an array
let clearButton = document.querySelector('.clear'); // get clear button
for (const div of divs) {
// div.addEventListener('click', capture, true); // add capture event
// div.addEventListener('click', bubble, false); // add bubble event
}
clearButton.addEventListener('click', clearOutput); // add event event (by default is false = bubble)