Skip to content

Commit 978e7b7

Browse files
committed
event object
1 parent 2c9585f commit 978e7b7

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

20_event_object.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,20 @@
55
// this keyword
66
// preventDefault() - prevents default behaviour
77

8-
const heading = document.querySelector('h1');
98
const btn = document.querySelector('.btn');
10-
const link = document.querySelector('#link');
11-
12-
heading.addEventListener('click', function (e) {
13-
e.currentTarget.classList.add('blue');
14-
});
9+
const heading = document.querySelector('h1');
10+
const link = document.getElementById('link');
1511

1612
btn.addEventListener('click', function (e) {
13+
// console.log(this); //<button class="btn">click me</button>
14+
// console.log(e.currentTarget); //<button class="btn">click me</button>
1715
e.currentTarget.classList.add('red');
18-
// for check type event listener
19-
console.log(e.type); //click
2016
});
2117

22-
// // callback as reference
23-
function callink(e) {
24-
// //will undefined and if link click not back again to top
25-
console.log(e.preventDefault());
18+
function callLink(e) {
19+
// here link can't scroll top again
20+
// will stuck cz preventDefault()
21+
e.preventDefault();
2622
}
2723

28-
link.addEventListener('click', callink);
24+
link.addEventListener('click', callLink);

0 commit comments

Comments
 (0)